470,586 Members | 1,636 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,586 developers. It's quick & easy.

Selecting an item in a drop down list

How do you force a drop down list to default to a particular item based on
its value?

I have a drop down list with options Yes, No, Maybe, All, and I would like
it to default to "All"

This is my code, what am I doing wrong?
ddlBilling.SelectedIndex =
ddlBilling.Items.IndexOf(ddlBilling.Items.FindByVa lue("All"))
Apr 10 '06 #1
3 1630
ddl.ClearSelection() // in case something else is selected
ddl.Items.FindByValue("All").Selected = true

-Brock
http://staff.develop.com/ballen

How do you force a drop down list to default to a particular item
based on its value?

I have a drop down list with options Yes, No, Maybe, All, and I would
like it to default to "All"

This is my code, what am I doing wrong?
ddlBilling.SelectedIndex =
ddlBilling.Items.IndexOf(ddlBilling.Items.FindByVa lue("All"))

Apr 10 '06 #2
That looks fine...is that the value of the dropdown or the text?

if it's the text, you need to use FindByText

Otherwise, where is this code?are you binding before?

Karl

--
http://www.openmymind.net/

"KatMagic" <SS********@yahoo.com> wrote in message
news:ue**************@TK2MSFTNGP05.phx.gbl...
How do you force a drop down list to default to a particular item based on
its value?

I have a drop down list with options Yes, No, Maybe, All, and I would like
it to default to "All"

This is my code, what am I doing wrong?
ddlBilling.SelectedIndex =
ddlBilling.Items.IndexOf(ddlBilling.Items.FindByVa lue("All"))

Apr 10 '06 #3
Thanks everyone you were very helpful. As you suggested, I was incorrectly
attempting to select by value, when "All" was a text value. Clearing the
selection and selecting by the actual value (0), worked! Thanks.

"KatMagic" <SS********@yahoo.com> wrote in message
news:ue**************@TK2MSFTNGP05.phx.gbl...
How do you force a drop down list to default to a particular item based on
its value?

I have a drop down list with options Yes, No, Maybe, All, and I would like
it to default to "All"

This is my code, what am I doing wrong?
ddlBilling.SelectedIndex =
ddlBilling.Items.IndexOf(ddlBilling.Items.FindByVa lue("All"))

Apr 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bogdan Zamfir | last post: by
3 posts views Thread by Novice Computer User | last post: by
3 posts views Thread by John Walker | last post: by
3 posts views Thread by mark.norgate | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.