By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,853 Members | 2,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,853 IT Pros & Developers. It's quick & easy.

Can I set a dropDownList to the TEXT rather than index?

P: n/a
I can set the selected item in a dropDownList to this:

DropDownList1.SelectedIndex = int

but is there a way to set it to the text value of the option instead? I've
looked in the documentation, and it appears the only way to set the selected
item is to use SelectedIndex.

-Darrel
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
This should work for you:
DropDownList1.Items.FindByText("foo").Selected = True

p.s. Make sure you have nothing selected or you will get an error... you
can't select 2 things at once:
DropDownList1.SelectedItem.Selected = False

Garett
http://www.aimx.com

"darrel" <no*****@hotmail.com> wrote in message
news:eQ**************@TK2MSFTNGP11.phx.gbl...
I can set the selected item in a dropDownList to this:

DropDownList1.SelectedIndex = int

but is there a way to set it to the text value of the option instead? I've
looked in the documentation, and it appears the only way to set the selected item is to use SelectedIndex.

-Darrel

Nov 18 '05 #2

P: n/a
Have you tried:
Me.cboName.SelectedValue = "Sometext"

Set the Datasource and then databind and then try the syntax above.
I think the Item collection is not filled until you call databind.
--
Joe Fallon

"darrel" <no*****@hotmail.com> wrote in message
news:eQ**************@TK2MSFTNGP11.phx.gbl...
I can set the selected item in a dropDownList to this:

DropDownList1.SelectedIndex = int

but is there a way to set it to the text value of the option instead? I've
looked in the documentation, and it appears the only way to set the selected item is to use SelectedIndex.

-Darrel

Nov 18 '05 #3

P: n/a
> Have you tried:
Me.cboName.SelectedValue = "Sometext"


Hmm...well, I've added this:

CountyData.ReadXml(MapPath("../Judges/JudgeCounty.xml"))
DropDownList1.DataSource = CountyData
DropDownList1.DataValueField = "CountyNumber"
DropDownList1.DataTextField = "CountyName"
DropDownList1.DataBind()
-->DropDownList1.SelectedValue =
(DropDownList1.SelectedItem.text)

But it doesn't work. Thanks, though! I'll keep digging!

-Darrel
Nov 18 '05 #4

P: n/a
> DropDownList1.Items.FindByText("foo").Selected = True

I added it here:

Try
CountyData.ReadXml(MapPath("../Judges/JudgeCounty.xml"))
DropDownList1.DataSource = CountyData
DropDownList1.DataValueField = "CountyNumber"
DropDownList1.DataTextField = "CountyName"
DropDownList1.DataBind()
-->
DropDownList1.Items.FindByText(DropDownList1.Selec tedItem.text).Selected =
True

However, no change. I'm guessing the 'selectedItem' isn't being passed to
the new page.

I did find that if I grab the query string instead, THEN it works...so,
thanks!

-Darrel
Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.