DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 16 Aug 2007 00:29:48 -0400,    posted on: microsoft.public.dotnet.framework.aspnet.webcontrols        back       

Thread Index
  1    Nathan Sokalski
          2    Ladislav Mrnka
          3    Ladislav Mrnka
                 4    Ladislav Mrnka
                 5    Ladislav Mrnka


ListItems and formatting   
I have become very frustrated with the ListItem control lately due to what 
happens when the Text property contains HTML tags. When the Text property 
contains HTML tags, or character codes such as  , they are converted to 
HTML (for example, <br/> would be rendered as <br/>). This can become 
very frustrating when you want to bold or underline part or all of a 
ListItem, which is not that uncommon of a task. Also, because this would be 
extremely trivial to do in an HTML file or classic ASP (and I am guessing 
most other server-side technologies), most clients will complain about it. 
Is there a reason that the ListItem does this? Why doesn't the ListItem have 
a Mode property that can be set to PassThrough, similar to what the Literal 
control has. I think this would solve the problem, and still allow the 
people that do want their HTML converted to have that option. But since the 
Mode property doesn't currently exist (I haven't looked at .NET 3.0, but 
since I still use VS2005 and .NET 2.0, that really doesn't matter yet), can 
someone tell me a way to use the ListItem and still do a little simple 
formatting like bolding and underlining (using simple stuff like the <b></b> 
and <u></u> tags) in my code? Thanks.
-- 
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/
Date:Thu, 16 Aug 2007 00:29:48 -0400   Author:  

RE: ListItems and formatting   
Hi Nathan,
all list controls inherits from class ListControl where you can find 
RenderContents method. I used Reflector to get code of this method and change 
it little bit to get new one in my own list control:

public class MyListBox : BulletedList
    {
        public MyListBox()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            ListItemCollection items = this.Items;
            int count = items.Count;
            if (count > 0)
            {
                bool flag = false;
                for (int i = 0; i < count; i++)
                {
                    ListItem item = items[i];
                    if (item.Enabled)
                    {
                        writer.WriteBeginTag("option");
                        if (item.Selected)
                        {
                            if (flag)
                            {
                                this.VerifyMultiSelect();
                            }
                            flag = true;
                            writer.WriteAttribute("selected", "selected");
                        }
                        writer.WriteAttribute("value", item.Value, true);
                        if (item.Attributes != null && item.Attributes.Count 

> 0)

                        {
                            item.Attributes.Render(writer);
                        }
                        if (this.Page != null)
                        {
                            
this.Page.ClientScript.RegisterForEventValidation(this.UniqueID, item.Value);
                        }
                        writer.Write('>');
                        writer.Write(item.Text);
                        writer.WriteEndTag("option");
                        writer.WriteLine();
                    }
                }
            }
        }
    }

This is only skelet of new class but it will solve your main problem. I 
think ListItem does not allow to set Mode because it is also used in ListBox 
and DropDownList where html tags are not rendered.

Regards,
Ladislav 

"Nathan Sokalski" wrote:


> I have become very frustrated with the ListItem control lately due to what 
> happens when the Text property contains HTML tags. When the Text property 
> contains HTML tags, or character codes such as  , they are converted to 
> HTML (for example, <br/> would be rendered as <br/>). This can become 
> very frustrating when you want to bold or underline part or all of a 
> ListItem, which is not that uncommon of a task. Also, because this would be 
> extremely trivial to do in an HTML file or classic ASP (and I am guessing 
> most other server-side technologies), most clients will complain about it. 
> Is there a reason that the ListItem does this? Why doesn't the ListItem have 
> a Mode property that can be set to PassThrough, similar to what the Literal 
> control has. I think this would solve the problem, and still allow the 
> people that do want their HTML converted to have that option. But since the 
> Mode property doesn't currently exist (I haven't looked at .NET 3.0, but 
> since I still use VS2005 and .NET 2.0, that really doesn't matter yet), can 
> someone tell me a way to use the ListItem and still do a little simple 
> formatting like bolding and underlining (using simple stuff like the <b></b> 
> and <u></u> tags) in my code? Thanks.
> -- 
> Nathan Sokalski
> njsokalski@hotmail.com
> http://www.nathansokalski.com/ 
> 
> 
> 
Date:Thu, 16 Aug 2007 18:01:39 -0700   Author:  

RE: ListItems and formatting   
Hi Nathan,
all list controls inherits from class ListControl where you can find 
RenderContents method. I used Reflector to get code of this method and change 
it little bit to get new one in my own list control:

public class MyListBox : BulletedList
    {
        public MyListBox()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            ListItemCollection items = this.Items;
            int count = items.Count;
            if (count > 0)
            {
                bool flag = false;
                for (int i = 0; i < count; i++)
                {
                    ListItem item = items[i];
                    if (item.Enabled)
                    {
                        writer.WriteBeginTag("option");
                        if (item.Selected)
                        {
                            if (flag)
                            {
                                this.VerifyMultiSelect();
                            }
                            flag = true;
                            writer.WriteAttribute("selected", "selected");
                        }
                        writer.WriteAttribute("value", item.Value, true);
                        if (item.Attributes != null && item.Attributes.Count 

> 0)

                        {
                            item.Attributes.Render(writer);
                        }
                        if (this.Page != null)
                        {
                            
this.Page.ClientScript.RegisterForEventValidation(this.UniqueID, item.Value);
                        }
                        writer.Write('>');
                        writer.Write(item.Text);
                        writer.WriteEndTag("option");
                        writer.WriteLine();
                    }
                }
            }
        }
    }

This is only skelet of new class but it will solve your main problem. I 
think ListItem does not allow to set Mode because it is also used in ListBox 
and DropDownList where html tags are not rendered.

Regards,
Ladislav 

"Nathan Sokalski" wrote:


> I have become very frustrated with the ListItem control lately due to what 
> happens when the Text property contains HTML tags. When the Text property 
> contains HTML tags, or character codes such as  , they are converted to 
> HTML (for example, <br/> would be rendered as <br/>). This can become 
> very frustrating when you want to bold or underline part or all of a 
> ListItem, which is not that uncommon of a task. Also, because this would be 
> extremely trivial to do in an HTML file or classic ASP (and I am guessing 
> most other server-side technologies), most clients will complain about it. 
> Is there a reason that the ListItem does this? Why doesn't the ListItem have 
> a Mode property that can be set to PassThrough, similar to what the Literal 
> control has. I think this would solve the problem, and still allow the 
> people that do want their HTML converted to have that option. But since the 
> Mode property doesn't currently exist (I haven't looked at .NET 3.0, but 
> since I still use VS2005 and .NET 2.0, that really doesn't matter yet), can 
> someone tell me a way to use the ListItem and still do a little simple 
> formatting like bolding and underlining (using simple stuff like the <b></b> 
> and <u></u> tags) in my code? Thanks.
> -- 
> Nathan Sokalski
> njsokalski@hotmail.com
> http://www.nathansokalski.com/ 
> 
> 
> 
Date:Thu, 16 Aug 2007 18:01:39 -0700   Author:  

RE: ListItems and formatting   
One more note:
As you can see my class derives from BulletedList (I used some of my 
previous code) but RenderContents is from ListControl. BulletedList has its 
own overriden version which is much more complicated to allow rendering items 
as hyperlinks, link buttons etc.

Ladislav Mrnka

"Ladislav Mrnka" wrote:


> Hi Nathan,
> all list controls inherits from class ListControl where you can find 
> RenderContents method. I used Reflector to get code of this method and change 
> it little bit to get new one in my own list control:
> 
> public class MyListBox : BulletedList
>     {
>         public MyListBox()
>         {
>             //
>             // TODO: Add constructor logic here
>             //
>         }
> 
>         protected override void RenderContents(HtmlTextWriter writer)
>         {
>             ListItemCollection items = this.Items;
>             int count = items.Count;
>             if (count > 0)
>             {
>                 bool flag = false;
>                 for (int i = 0; i < count; i++)
>                 {
>                     ListItem item = items[i];
>                     if (item.Enabled)
>                     {
>                         writer.WriteBeginTag("option");
>                         if (item.Selected)
>                         {
>                             if (flag)
>                             {
>                                 this.VerifyMultiSelect();
>                             }
>                             flag = true;
>                             writer.WriteAttribute("selected", "selected");
>                         }
>                         writer.WriteAttribute("value", item.Value, true);
>                         if (item.Attributes != null && item.Attributes.Count 
> > 0)
>                         {
>                             item.Attributes.Render(writer);
>                         }
>                         if (this.Page != null)
>                         {
>                             
> this.Page.ClientScript.RegisterForEventValidation(this.UniqueID, item.Value);
>                         }
>                         writer.Write('>');
>                         writer.Write(item.Text);
>                         writer.WriteEndTag("option");
>                         writer.WriteLine();
>                     }
>                 }
>             }
>         }
>     }
> 
> This is only skelet of new class but it will solve your main problem. I 
> think ListItem does not allow to set Mode because it is also used in ListBox 
> and DropDownList where html tags are not rendered.
> 
> Regards,
> Ladislav 
> 
> "Nathan Sokalski" wrote:
> 
> > I have become very frustrated with the ListItem control lately due to what 
> > happens when the Text property contains HTML tags. When the Text property 
> > contains HTML tags, or character codes such as  , they are converted to 
> > HTML (for example, <br/> would be rendered as <br/>). This can become 
> > very frustrating when you want to bold or underline part or all of a 
> > ListItem, which is not that uncommon of a task. Also, because this would be 
> > extremely trivial to do in an HTML file or classic ASP (and I am guessing 
> > most other server-side technologies), most clients will complain about it. 
> > Is there a reason that the ListItem does this? Why doesn't the ListItem have 
> > a Mode property that can be set to PassThrough, similar to what the Literal 
> > control has. I think this would solve the problem, and still allow the 
> > people that do want their HTML converted to have that option. But since the 
> > Mode property doesn't currently exist (I haven't looked at .NET 3.0, but 
> > since I still use VS2005 and .NET 2.0, that really doesn't matter yet), can 
> > someone tell me a way to use the ListItem and still do a little simple 
> > formatting like bolding and underlining (using simple stuff like the <b></b> 
> > and <u></u> tags) in my code? Thanks.
> > -- 
> > Nathan Sokalski
> > njsokalski@hotmail.com
> > http://www.nathansokalski.com/ 
> > 
> > 
> > 
Date:Thu, 16 Aug 2007 18:23:30 -0700   Author:  

RE: ListItems and formatting   
One more note:
As you can see my class derives from BulletedList (I used some of my 
previous code) but RenderContents is from ListControl. BulletedList has its 
own overriden version which is much more complicated to allow rendering items 
as hyperlinks, link buttons etc.

Ladislav Mrnka

"Ladislav Mrnka" wrote:


> Hi Nathan,
> all list controls inherits from class ListControl where you can find 
> RenderContents method. I used Reflector to get code of this method and change 
> it little bit to get new one in my own list control:
> 
> public class MyListBox : BulletedList
>     {
>         public MyListBox()
>         {
>             //
>             // TODO: Add constructor logic here
>             //
>         }
> 
>         protected override void RenderContents(HtmlTextWriter writer)
>         {
>             ListItemCollection items = this.Items;
>             int count = items.Count;
>             if (count > 0)
>             {
>                 bool flag = false;
>                 for (int i = 0; i < count; i++)
>                 {
>                     ListItem item = items[i];
>                     if (item.Enabled)
>                     {
>                         writer.WriteBeginTag("option");
>                         if (item.Selected)
>                         {
>                             if (flag)
>                             {
>                                 this.VerifyMultiSelect();
>                             }
>                             flag = true;
>                             writer.WriteAttribute("selected", "selected");
>                         }
>                         writer.WriteAttribute("value", item.Value, true);
>                         if (item.Attributes != null && item.Attributes.Count 
> > 0)
>                         {
>                             item.Attributes.Render(writer);
>                         }
>                         if (this.Page != null)
>                         {
>                             
> this.Page.ClientScript.RegisterForEventValidation(this.UniqueID, item.Value);
>                         }
>                         writer.Write('>');
>                         writer.Write(item.Text);
>                         writer.WriteEndTag("option");
>                         writer.WriteLine();
>                     }
>                 }
>             }
>         }
>     }
> 
> This is only skelet of new class but it will solve your main problem. I 
> think ListItem does not allow to set Mode because it is also used in ListBox 
> and DropDownList where html tags are not rendered.
> 
> Regards,
> Ladislav 
> 
> "Nathan Sokalski" wrote:
> 
> > I have become very frustrated with the ListItem control lately due to what 
> > happens when the Text property contains HTML tags. When the Text property 
> > contains HTML tags, or character codes such as  , they are converted to 
> > HTML (for example, <br/> would be rendered as <br/>). This can become 
> > very frustrating when you want to bold or underline part or all of a 
> > ListItem, which is not that uncommon of a task. Also, because this would be 
> > extremely trivial to do in an HTML file or classic ASP (and I am guessing 
> > most other server-side technologies), most clients will complain about it. 
> > Is there a reason that the ListItem does this? Why doesn't the ListItem have 
> > a Mode property that can be set to PassThrough, similar to what the Literal 
> > control has. I think this would solve the problem, and still allow the 
> > people that do want their HTML converted to have that option. But since the 
> > Mode property doesn't currently exist (I haven't looked at .NET 3.0, but 
> > since I still use VS2005 and .NET 2.0, that really doesn't matter yet), can 
> > someone tell me a way to use the ListItem and still do a little simple 
> > formatting like bolding and underlining (using simple stuff like the <b></b> 
> > and <u></u> tags) in my code? Thanks.
> > -- 
> > Nathan Sokalski
> > njsokalski@hotmail.com
> > http://www.nathansokalski.com/ 
> > 
> > 
> > 
Date:Thu, 16 Aug 2007 18:23:30 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us