472,975 Members | 1,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,975 software developers and data experts.

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

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
Nov 21 '06 #1
7 2739
Unfortunetly, you're best bet will be to add this value in codebehind...

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

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Jim in Arizona" <ti*******@hotmail.comwrote in message
news:Ot**************@TK2MSFTNGP02.phx.gbl...
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
Nov 21 '06 #2
Karl Seguin wrote:
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
Nov 21 '06 #3

"Karl Seguin" <ka********@removeopenmymindremovemetoo.andmenetwr ote in
message news:%2****************@TK2MSFTNGP06.phx.gbl...
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.
Nov 21 '06 #4

"Karl Seguin" <ka********@removeopenmymindremovemetoo.andmenetwr ote in
message news:%2****************@TK2MSFTNGP06.phx.gbl...
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.
Nov 21 '06 #5
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.openmymind.net/
http://www.codebetter.com/
"Badass Scotsman" <ba****@yo.comwrote in message
news:8r*****************@text.news.blueyonder.co.u k...
>
"Karl Seguin" <ka********@removeopenmymindremovemetoo.andmenetwr ote in
message news:%2****************@TK2MSFTNGP06.phx.gbl...
>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.
Nov 22 '06 #6
Thanks Karl,

Will let you know how I get on.

Gary.
"Karl Seguin" <ka********@removeopenmymindremovemetoo.andmenetwr ote in
message news:eM**************@TK2MSFTNGP03.phx.gbl...
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.openmymind.net/
http://www.codebetter.com/
"Badass Scotsman" <ba****@yo.comwrote in message
news:8r*****************@text.news.blueyonder.co.u k...
>>
"Karl Seguin" <ka********@removeopenmymindremovemetoo.andmenetwr ote in
message news:%2****************@TK2MSFTNGP06.phx.gbl...
>>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.

Nov 22 '06 #7

"Karl Seguin" <ka********@removeopenmymindremovemetoo.andmenetwr ote in
message news:eM**************@TK2MSFTNGP03.phx.gbl...
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.
Nov 22 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.