Selecting an item in a drop down list

K

KatMagic

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.FindByValue("All"))
 
B

Brock Allen

ddl.ClearSelection() // in case something else is selected
ddl.Items.FindByValue("All").Selected = true
 
K

Karl Seguin [MVP]

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
 
K

KatMagic

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.
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top