Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Controls / February 2008

Tip: Looking for answers? Try searching our database.

How to prevent BulletedList control from encoding HTML?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Doh - 14 Feb 2008 01:47 GMT
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.
Phil H - 14 Feb 2008 22:30 GMT
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
John Doh - 15 Feb 2008 00:39 GMT
Thanks Phil.

> Hi
>
[quoted text clipped - 48 lines]
>
> HTH
Lars - 15 Feb 2008 21:04 GMT
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.

<asp:DataList 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>
</asp:DataList>

> Thanks Phil.
>
[quoted text clipped - 50 lines]
>>
>> HTH

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.