<asp:ListItem> in v2

M

Mark Rae

Hi,

Has the <asp:DropDownList> - <asp:ListItem> functionality changed in v2? In
v1.1, the following works as expected:

<asp:DropDownList ID="cmbStatus" Runat=server EnableViewState=False>
<asp:ListItem Value=0>&nbsp;</asp:ListItem>
<asp:ListItem Value=1>Awaiting</asp:ListItem>
<asp:ListItem Value=2>Current</asp:ListItem>
<asp:ListItem Value=3>Terminated</asp:ListItem>
</asp:DropDownList>

i.e. three options with a blank option at the top.

However, in v2, the first option (i.e. the one which should be blank)
displays with a zero instead of the non-breaking space - when I do a View
Source, I can see that &nbsp; has been replaced by 0.

Is this normal?

Mark
 
S

S. Justin Gengo [MCP]

Mark,

Spaces get trimmed off of drop down lists autmatically. So the list must
think it's completely empty and then substitutes the value.

Yes, I think this is by design. There is a way to encode a space so it shows
up in a drop down list. I have a StringUtilities object that I give away on
my website and one of the routines in it is a way to pad encode spaces so
that a drop down list may be padded.

Here's the routine:

Private Function Pad(ByVal server As HttpServerUtility, ByVal numberOfSpaces
As Int32) As String
Try
Dim Spaces As String
For items As Int32 = 1 To numberOfSpaces
Spaces &= "&nbsp;"
Next
Return server.HtmlDecode(Spaces)
Catch ex As Exception
Throw ex
End Try

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
M

Mark Rae

Spaces get trimmed off of drop down lists autmatically.

Since when? They certainly didn't in v1.x
So the list must think it's completely empty and then substitutes the
value.

That makes no sense to me...
Yes, I think this is by design.

How intensely irritating.
There is a way to encode a space so it shows up in a drop down list.

Yeah, one line of code will do that...
<DropDownList>.Items.Insert(0, new ListItem("", "0"));

That's not what I'm talking about - I'm talking about creating the
DropDownList and its ListItems in the source, not the code behind...
 
S

S. Justin Gengo [MCP]

Mark,

In that case, did you fail to try the obvious?

<asp:DropDownList ID="Test" runat="server">

<asp:ListItem Value="0" Text=""></asp:ListItem>

<asp:ListItem Value="1" Text="One"></asp:ListItem>

</asp:DropDownList>



Works just fine.


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

S. Justin Gengo [MCP]

Then something is wrong with your install.

Did you take a close look at the code? I'm setting the text parameter of the
list item instead of putting the text between the list item tags.

I've tested it on three machines each running visual studio 2005 and tested
placing it out on a test website and it works on all.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top