<asp:ListItem Value="0">blank choice</asp:ListItem> ?

J

Jim in Arizona

Using this:
<asp:ListItem Value="0"> </asp:ListItem>

as long as I have a value listed and leave the area between the tags
blank, when viewed the DropDownList will show a 0 as a choice. I want it
to be blank.

I've tried doing this:
<asp:ListItem Value="0">&nbsp;</asp:ListItem>

and tried this:
<asp:ListItem Value="0"> </asp:ListItem>

and putting nothing in there:
<asp:ListItem Value="0"> </asp:ListItem>

In all cases, a zero shows up as the first selection.

How can I retain the value of zero but keep the choice blank?

Thanks,
Jim
 
K

Karl Seguin

Unfortunetly, you're best bet will be to add this value in codebehind...

myDropDown.Items.Insert(0, New ListItem("", 0))

Karl
 
J

Jim in Arizona

Karl said:
Unfortunetly, you're best bet will be to add this value in codebehind...

myDropDown.Items.Insert(0, New ListItem("", 0))

Karl

Well, that's a lot easier and cleaner than what I ended up doing:


Dim strddlList As String = ""

If ddlList.SelectedItem.Text = "" Then
strddlList = "0"
Else
strddlList = ddlList.SelectedValue
End If


Thanks for your response.

Jim
 
B

Badass Scotsman

Karl Seguin said:
Unfortunetly, you're best bet will be to add this value in codebehind...

myDropDown.Items.Insert(0, New ListItem("", 0))

Karl


Karl,

Would your example work in C# ?

It looks like it could be adapted somewhat to help me with a small problem.

I want to create a list as follows:

<asp:ListItem Value="100">100</asp:ListItem>
<asp:ListItem Value="200">200</asp:ListItem>
<asp:ListItem Value="300">300</asp:ListItem>
And so on, until I get to
<asp:ListItem Value="10000">10000</asp:ListItem>

I dont want to have to create it manually, as I will no doubt have an error
crop up somewhere.

Gary.
 
B

Badass Scotsman

Karl Seguin said:
Unfortunetly, you're best bet will be to add this value in codebehind...

myDropDown.Items.Insert(0, New ListItem("", 0))

Karl


I have used your example to try and do the auto list:

==================================
protected override void OnLoad(EventArgs e)
{
int a = 0;
while (a < 100)
{
MyDropDown.Items.Insert(0, new ListItem(""+a+"", ""+a+""));
a++;
}
}
==================================

Do you know how I might go about increasing by an increment of 100 at a time
instead of 1?

New to .NET.

Ta,

Gary.
 
K

Karl Seguin

you could do a+=100

but a for loop is probably better for what you want (only a bit though...no
big deal if you prefer a while loop...)

Also, you can use Add instead of Insert (insert places it at the index
specified in the first parameter...my guess is you just wanna append them
one after another)

for (int i = 100; i < 10000; i+=100)
{
MyDropDow.Items.Add(i.ToString());
}

I started at 100 'cuz that's what your example looked like you wanted...you
could do int i = 0 if you want a 0 in there...
also note that I'm not creating a new ListItem, the Add method also accepts
a single string when the text and value are the same thing...just a
convinience...


Karl
 
B

Badass Scotsman

Karl Seguin said:
you could do a+=100

but a for loop is probably better for what you want (only a bit
though...no big deal if you prefer a while loop...)

Also, you can use Add instead of Insert (insert places it at the index
specified in the first parameter...my guess is you just wanna append them
one after another)

for (int i = 100; i < 10000; i+=100)
{
MyDropDow.Items.Add(i.ToString());
}

I started at 100 'cuz that's what your example looked like you
wanted...you could do int i = 0 if you want a 0 in there...
also note that I'm not creating a new ListItem, the Add method also
accepts a single string when the text and value are the same thing...just
a convinience...


Karl

Works like a charm, thanks for your help - you guys don't know how much it
means. I like to think of Usenet as an interactive "learn as you go" type
of book, one that takes you through your specific problem in simple and easy
to understand terms. Without people willingto help, I would be much further
behind in my (two week old) knowledge...

Gary.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top