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

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

Post by Jim in Ari » Thu, 23 Nov 2006 05:56:54


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"> </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
 
 
 

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

Post by Karl Segui » Thu, 23 Nov 2006 06:39:05

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

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

Karl
--
http://www.yqcomputer.com/
http://www.yqcomputer.com/

 
 
 

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

Post by Jim in Ari » Thu, 23 Nov 2006 06:58:10


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
 
 
 

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

Post by Badass Sco » Thu, 23 Nov 2006 07:33:17


"Karl Seguin" < XXXX@XXXXX.COM > wrote in



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.
 
 
 

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

Post by Badass Sco » Thu, 23 Nov 2006 07:52:52


"Karl Seguin" < XXXX@XXXXX.COM > wrote in



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.
 
 
 

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

Post by Karl Segui » Thu, 23 Nov 2006 13:18:47

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

--
http://www.yqcomputer.com/
http://www.yqcomputer.com/
 
 
 

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

Post by Badass Sco » Thu, 23 Nov 2006 17:10:16

Thanks Karl,

Will let you know how I get on.

Gary.


"Karl Seguin" < XXXX@XXXXX.COM > wrote in
 
 
 

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

Post by Badass Sco » Thu, 23 Nov 2006 17:31:48


"Karl Seguin" < XXXX@XXXXX.COM > wrote in


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.