364,032 Members | 4401 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

How to add " " to list item text

Naveen K Kohli
P: n/a
Naveen K Kohli
I am try to set the text of the drop down list item as

ListItem li = new ListItem();
li.Text = " "+"MyValue";

myDropDown.Items.Add("li);

The intent is to add a spacing in front of the text. Its not doing what I am
trying to do. The text shows up as "&ampMyValue"

How can this be accomplished?


Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


Naveen K Kohli
P: n/a
Naveen K Kohli
Thanks Justin,
I tried that. It truncates the blank spaces at the start. In regular ASP
apps I was able to do..

<option>&nbsp;&nbsp;MyValue

I am trying to do the same thing with DropdownList control


"S. Justin Gengo" <sjgengo@aboutfortunate.com> wrote in message
news:umUWYZRYDHA.4020@tk2msftngp13.phx.gbl...[color=blue]
> Naveen,
>
> Drop down lists don't use the same encoding as regular html on the page.
>
> Just add a regular " " space.
>
> Sincerely,
>
>
> --
> S. Justin Gengo, MCP
> Web Developer
>
> Free code library at:
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzche
>
>
> "Naveen K Kohli" <naveenkohli@hotmail.com> wrote in message
> news:ONxW1QRYDHA.1492@TK2MSFTNGP12.phx.gbl...[color=green]
> > I am try to set the text of the drop down list item as
> >
> > ListItem li = new ListItem();
> > li.Text = "&nbsp;"+"MyValue";
> >
> > myDropDown.Items.Add("li);
> >
> > The intent is to add a spacing in front of the text. Its not doing what[/color][/color]
I[color=blue]
> am[color=green]
> > trying to do. The text shows up as "&ampMyValue"
> >
> > How can this be accomplished?
> >
> >[/color]
>
>[/color]


Nov 17 '05 #2

Tyrone
P: n/a
Tyrone
What I think the issue is is that you are using the "+" to
add both strings..i think you must use the & char.

Well in VB.Net in C# your right on the money I think..you
use the "+"..but you didn't specify any language

ListItem li = new ListItem();
li.Text = "&nbsp;" & "MyValue";

myDropDown.Items.Add("li");
[color=blue]
>-----Original Message-----
>Thanks Justin,
>I tried that. It truncates the blank spaces at the start.[/color]
In regular ASP[color=blue]
>apps I was able to do..
>
><option> MyValue
>
>I am trying to do the same thing with DropdownList control
>
>
>"S. Justin Gengo" <sjgengo@aboutfortunate.com> wrote in[/color]
message[color=blue]
>news:umUWYZRYDHA.4020@tk2msftngp13.phx.gbl...[color=green]
>> Naveen,
>>
>> Drop down lists don't use the same encoding as regular[/color][/color]
html on the page.[color=blue][color=green]
>>
>> Just add a regular " " space.
>>
>> Sincerely,
>>
>>
>> --
>> S. Justin Gengo, MCP
>> Web Developer
>>
>> Free code library at:
>> www.aboutfortunate.com
>>
>> "Out of chaos comes order."
>> Nietzche
>>
>>
>> "Naveen K Kohli" <naveenkohli@hotmail.com> wrote in[/color][/color]
message[color=blue][color=green]
>> news:ONxW1QRYDHA.1492@TK2MSFTNGP12.phx.gbl...[color=darkred]
>> > I am try to set the text of the drop down list item as
>> >
>> > ListItem li = new ListItem();
>> > li.Text = " "+"MyValue";
>> >
>> > myDropDown.Items.Add("li);
>> >
>> > The intent is to add a spacing in front of the text.[/color][/color][/color]
Its not doing what[color=blue]
>I[color=green]
>> am[color=darkred]
>> > trying to do. The text shows up as "&MyValue"
>> >
>> > How can this be accomplished?
>> >
>> >[/color]
>>
>>[/color]
>
>
>.
>[/color]
Nov 17 '05 #3

Naveen K Kohli
P: n/a
Naveen K Kohli
I think choice of language was clear. I don't think that VB uses ";" at the
end of statement. Thats not the point.
ListItem truncates the leading spaces. And if you have any HTML decoded
string, it will encode it and display as "&ampndp;". The solution to this
issue can be found at floowing link.,

http://www.netomatix.com/IndentDropdownList.aspx

Naveen

"Tyrone" <t_davisjr@hotmail.com> wrote in message
news:08a901c36134$43d82be0$a101280a@phx.gbl...[color=blue]
> What I think the issue is is that you are using the "+" to
> add both strings..i think you must use the & char.
>
> Well in VB.Net in C# your right on the money I think..you
> use the "+"..but you didn't specify any language
>
> ListItem li = new ListItem();
> li.Text = "&nbsp;" & "MyValue";
>
> myDropDown.Items.Add("li");
>[color=green]
> >-----Original Message-----
> >Thanks Justin,
> >I tried that. It truncates the blank spaces at the start.[/color]
> In regular ASP[color=green]
> >apps I was able to do..
> >
> ><option> MyValue
> >
> >I am trying to do the same thing with DropdownList control
> >
> >
> >"S. Justin Gengo" <sjgengo@aboutfortunate.com> wrote in[/color]
> message[color=green]
> >news:umUWYZRYDHA.4020@tk2msftngp13.phx.gbl...[color=darkred]
> >> Naveen,
> >>
> >> Drop down lists don't use the same encoding as regular[/color][/color]
> html on the page.[color=green][color=darkred]
> >>
> >> Just add a regular " " space.
> >>
> >> Sincerely,
> >>
> >>
> >> --
> >> S. Justin Gengo, MCP
> >> Web Developer
> >>
> >> Free code library at:
> >> www.aboutfortunate.com
> >>
> >> "Out of chaos comes order."
> >> Nietzche
> >>
> >>
> >> "Naveen K Kohli" <naveenkohli@hotmail.com> wrote in[/color][/color]
> message[color=green][color=darkred]
> >> news:ONxW1QRYDHA.1492@TK2MSFTNGP12.phx.gbl...
> >> > I am try to set the text of the drop down list item as
> >> >
> >> > ListItem li = new ListItem();
> >> > li.Text = " "+"MyValue";
> >> >
> >> > myDropDown.Items.Add("li);
> >> >
> >> > The intent is to add a spacing in front of the text.[/color][/color]
> Its not doing what[color=green]
> >I[color=darkred]
> >> am
> >> > trying to do. The text shows up as "&MyValue"
> >> >
> >> > How can this be accomplished?
> >> >
> >> >
> >>
> >>[/color]
> >
> >
> >.
> >[/color][/color]


Nov 17 '05 #4

John Timney \(Microsoft MVP\)
P: n/a
John Timney \(Microsoft MVP\)
The code below should help you out.
--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------

<%@ Page Language="VB" Debug="true" %>
<script language=VB runat=server>

Sub Page_Load(Sender As Object, E As EventArgs)

Dim Padding As String
Dim writer As New System.IO.StringWriter()
Dim DecodedString As String

Padding = "&nbsp;&nbsp;"
Server.HtmlDecode(Padding, writer)
Padding = writer.ToString()

myDropDownList2.Items.Add(Padding & " MVP's")

Padding = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;"
Server.HtmlDecode(Padding, writer)
Padding = writer.ToString()

myDropDownList2.Items.Add(Padding & " MVP's")

myDropDownList2.Items.Add("MVP's" & Padding & "Do Their best")

End Sub

</script>
<html>
<head><title>Padding DropListBox</title></head>
<body><form fred runat="server"><asp:dropdownlist id="MyDropDownList2"
runat="server"/></form></body>
</html>



Nov 17 '05 #5

Naveen K Kohli
P: n/a
Naveen K Kohli
John,
I did try this before posting the code. Nothing seemed to work. &nbsp; did
not show up as spaces.

Thanks.

"John Timney (Microsoft MVP)" <timneyj@despammed.com> wrote in message
news:euli5UrYDHA.1640@TK2MSFTNGP10.phx.gbl...[color=blue]
> The code below should help you out.
> --
> Regards
>
> John Timney (Microsoft ASP.NET MVP)
> ----------------------------------------------
> <shameless_author_plug>
> Professional .NET for Java Developers with C#
> ISBN:1-861007-91-4
> Professional Windows Forms
> ISBN: 1861005547
> Professional JSP 2nd Edition
> ISBN: 1861004958
> Professional JSP
> ISBN: 1861003625
> Beginning JSP Web Development
> ISBN: 1861002092
> </shameless_author_plug>
> ----------------------------------------------
>
> <%@ Page Language="VB" Debug="true" %>
> <script language=VB runat=server>
>
> Sub Page_Load(Sender As Object, E As EventArgs)
>
> Dim Padding As String
> Dim writer As New System.IO.StringWriter()
> Dim DecodedString As String
>
> Padding = "&nbsp;&nbsp;"
> Server.HtmlDecode(Padding, writer)
> Padding = writer.ToString()
>
> myDropDownList2.Items.Add(Padding & " MVP's")
>
> Padding = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;"
> Server.HtmlDecode(Padding, writer)
> Padding = writer.ToString()
>
> myDropDownList2.Items.Add(Padding & " MVP's")
>
> myDropDownList2.Items.Add("MVP's" & Padding & "Do Their best")
>
> End Sub
>
> </script>
> <html>
> <head><title>Padding DropListBox</title></head>
> <body><form fred runat="server"><asp:dropdownlist id="MyDropDownList2"
> runat="server"/></form></body>
> </html>
>
>
>[/color]


Nov 17 '05 #6

Post your reply

Help answer this question



Didn't find the answer to your ASP.NET question?

You can also browse similar questions: ASP.NET