Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Selecting an item in a drop down list

Reply
Thread Tools

Selecting an item in a drop down list

 
 
KatMagic
Guest
Posts: n/a
 
      04-10-2006
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"))


 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      04-10-2006
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"))



 
Reply With Quote
 
 
 
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      04-10-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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"))
>
>



 
Reply With Quote
 
KatMagic
Guest
Posts: n/a
 
      04-11-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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"))
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
retrive preselected value in second drop down list from the first drop down list weiwei ASP .Net 0 01-05-2007 07:29 PM
Auto Drop down a Drop Down List xxbmichae1@supergambler.com Javascript 5 11-23-2005 01:35 AM
Selecting Item in Drop Down List Box Andrew HTML 2 04-15-2005 04:46 PM
Re: Selecting an item in a drop down list Natty Gur ASP .Net 1 08-18-2003 02:40 PM
Selecting an item in a drop down list Bogdan Zamfir ASP .Net 2 08-17-2003 10:06 PM



Advertisments