Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > How to prevent BulletedList control from encoding HTML?

Reply
Thread Tools

How to prevent BulletedList control from encoding HTML?

 
 
John Doh
Guest
Posts: n/a
 
      02-14-2008
Is it possible to prevent the ListItem that I add to a BulletedList control
to be HTML encoded? I want to add text with <br> tags for example.

Thanks.

 
Reply With Quote
 
 
 
 
Phil H
Guest
Posts: n/a
 
      02-14-2008
Hi

It would appear that the Text property of the ListItem will only allow
a single line of plain text. It converts < > to &lt; and &gt;
respectively (so renders them visibly on the page as < > ) and will
ignore escaped control characters (e.g. \n in C#).

This is unlike the behaviour of the Text property of say a Label
control which does allow HTML tags in string literals and will render
them unfiltered. (The label control also puts line breaks in where
there are \n escape characters)

Without knowing more about the context in which you are trying to
achieve this I can only suggest you consider building your list in
code using a Literal control (designed for programmatic generation of
raw HTML). For example:

Assume you have placed a Literal control named ALiteral on the page
using the designer

ALiteral.Text = "<ul>";
ALiteral.Text += "<li>Line 1 - some text<br />continued on next line
with no bullet</li>";

//... other lines

ALiteral.Text += "</ul>";

In fact here is another example where the list is generated
programmatically from a DataTable using a DataSet
(It produces a bulleted list of 'Myths' surround a particular topic
taken from a project I am working on. Line breaks are put in after
each myth and the truth text on the line underneath. The bullets and
the italicised text help emphasise each fallacious statement on the
first line of each entry in the list:

DataSet1TableAdapters.mythsTableAdapter taMyths
= new DataSet1TableAdapters.mythsTableAdapter();
DataSet1.mythsDataTable dtMyths = taMyths.GetData();

Literal1.Text = "<ul>";
foreach (DataRowView drvMyth in dtMyths.DefaultView)
{
Literal1.Text += "<li><em>" +
(string)drvMyth["myth_text"] + "</em><br /
>" +

(string)drvMyth["reality_text"] + "</
li>";
}
Literal1.Text += "</ul>";


HTH
 
Reply With Quote
 
 
 
 
John Doh
Guest
Posts: n/a
 
      02-15-2008
Thanks Phil.


"Phil H" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> It would appear that the Text property of the ListItem will only allow
> a single line of plain text. It converts < > to &lt; and &gt;
> respectively (so renders them visibly on the page as < > ) and will
> ignore escaped control characters (e.g. \n in C#).
>
> This is unlike the behaviour of the Text property of say a Label
> control which does allow HTML tags in string literals and will render
> them unfiltered. (The label control also puts line breaks in where
> there are \n escape characters)
>
> Without knowing more about the context in which you are trying to
> achieve this I can only suggest you consider building your list in
> code using a Literal control (designed for programmatic generation of
> raw HTML). For example:
>
> Assume you have placed a Literal control named ALiteral on the page
> using the designer
>
> ALiteral.Text = "<ul>";
> ALiteral.Text += "<li>Line 1 - some text<br />continued on next line
> with no bullet</li>";
>
> //... other lines
>
> ALiteral.Text += "</ul>";
>
> In fact here is another example where the list is generated
> programmatically from a DataTable using a DataSet
> (It produces a bulleted list of 'Myths' surround a particular topic
> taken from a project I am working on. Line breaks are put in after
> each myth and the truth text on the line underneath. The bullets and
> the italicised text help emphasise each fallacious statement on the
> first line of each entry in the list:
>
> DataSet1TableAdapters.mythsTableAdapter taMyths
> = new DataSet1TableAdapters.mythsTableAdapter();
> DataSet1.mythsDataTable dtMyths = taMyths.GetData();
>
> Literal1.Text = "<ul>";
> foreach (DataRowView drvMyth in dtMyths.DefaultView)
> {
> Literal1.Text += "<li><em>" +
> (string)drvMyth["myth_text"] + "</em><br /
>>" +

> (string)drvMyth["reality_text"] + "</
> li>";
> }
> Literal1.Text += "</ul>";
>
>
> HTH


 
Reply With Quote
 
Lars
Guest
Posts: n/a
 
      02-15-2008
HI

I have the very same problem. My database stores html commands for links
that I show in a DataList. The DataList canhandle to show pure HTML code bit
not GridView or FormView. After I bought a instroduction book that I'm
reading I got some ideas how to solve part of the problem. You could use
Responce.Write( anHTMLString ); to write plain html to the responce. Just as
in old plain ASP.


I suggest you use a DataList in stead of a DataView. That is unless you have
to change the value in a database. Then you have som work to do.


<aspataList ID="DataList1" runat="server" BackColor="White"
BorderColor="White" BorderStyle="Ridge" BorderWidth="2px"
CellPadding="3"
CellSpacing="1" DataKeyField="HTML" DataSourceID="sdsMusicFiles">
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<EditItemStyle BackColor="#DEDFDE" Font-Bold="False" Font-Italic="False"
Font-Overline="False" Font-Strikeout="False" Font-Underline="False"
ForeColor="Black" />
<AlternatingItemStyle BackColor="#DEDFDE" Font-Bold="False"
Font-Italic="False"
Font-Overline="False" Font-Strikeout="False" Font-Underline="False"
ForeColor="Black" />
<ItemStyle BackColor="#DEDFDE" ForeColor="Black" />
<EditItemTemplate>
HTML<asp:TextBox ID="tbEditHTML" runat="server"
ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<br />
URL<asp:TextBox ID="tbEditURL" runat="server"
ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<br />
Name<asp:TextBox ID="tbEditFilename" runat="server"
ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<br />
Flagga<asp:TextBox ID="tbEditFlag" runat="server"
ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<br />
Kompositör<asp:TextBox ID="tbEditAuthour" runat="server"
ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<br />
</EditItemTemplate>
<SelectedItemStyle BackColor="#DEDFDE" Font-Bold="True"
Font-Italic="False"
Font-Overline="False" Font-Strikeout="False" Font-Underline="False"
ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<ItemTemplate>
<asp:Label ID="HTMLLabel" runat="server" Text='<%# Eval("HTML",
"{0}") %>' />
<br />
</ItemTemplate>
</aspataList>





"John Doh" <(E-Mail Removed)> skrev i meddelandet
news:(E-Mail Removed)...
> Thanks Phil.
>
>
> "Phil H" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi
>>
>> It would appear that the Text property of the ListItem will only allow
>> a single line of plain text. It converts < > to &lt; and &gt;
>> respectively (so renders them visibly on the page as < > ) and will
>> ignore escaped control characters (e.g. \n in C#).
>>
>> This is unlike the behaviour of the Text property of say a Label
>> control which does allow HTML tags in string literals and will render
>> them unfiltered. (The label control also puts line breaks in where
>> there are \n escape characters)
>>
>> Without knowing more about the context in which you are trying to
>> achieve this I can only suggest you consider building your list in
>> code using a Literal control (designed for programmatic generation of
>> raw HTML). For example:
>>
>> Assume you have placed a Literal control named ALiteral on the page
>> using the designer
>>
>> ALiteral.Text = "<ul>";
>> ALiteral.Text += "<li>Line 1 - some text<br />continued on next line
>> with no bullet</li>";
>>
>> //... other lines
>>
>> ALiteral.Text += "</ul>";
>>
>> In fact here is another example where the list is generated
>> programmatically from a DataTable using a DataSet
>> (It produces a bulleted list of 'Myths' surround a particular topic
>> taken from a project I am working on. Line breaks are put in after
>> each myth and the truth text on the line underneath. The bullets and
>> the italicised text help emphasise each fallacious statement on the
>> first line of each entry in the list:
>>
>> DataSet1TableAdapters.mythsTableAdapter taMyths
>> = new DataSet1TableAdapters.mythsTableAdapter();
>> DataSet1.mythsDataTable dtMyths = taMyths.GetData();
>>
>> Literal1.Text = "<ul>";
>> foreach (DataRowView drvMyth in dtMyths.DefaultView)
>> {
>> Literal1.Text += "<li><em>" +
>> (string)drvMyth["myth_text"] + "</em><br /
>>>" +

>> (string)drvMyth["reality_text"] + "</
>> li>";
>> }
>> Literal1.Text += "</ul>";
>>
>>
>> HTH

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Problem with the BulletedList control Nathan Sokalski ASP .Net 0 03-15-2007 08:52 PM
Nesting the BulletedList control Nathan Sokalski ASP .Net 0 03-13-2007 08:55 PM
BulletedList inside BulletedList Stan SR ASP .Net 2 08-31-2006 05:36 AM
BulletedList control not showing bullets? Rob R. Ainscough ASP .Net Web Controls 1 05-23-2006 09:11 PM



Advertisments