Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Can I set a dropDownList to the TEXT rather than index?

Reply
Thread Tools

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

 
 
darrel
Guest
Posts: n/a
 
      05-03-2004
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


 
Reply With Quote
 
 
 
 
Garett Rogers
Guest
Posts: n/a
 
      05-03-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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
>
>



 
Reply With Quote
 
 
 
 
Joe Fallon
Guest
Posts: n/a
 
      05-03-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
darrel
Guest
Posts: n/a
 
      05-04-2004
> 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


 
Reply With Quote
 
darrel
Guest
Posts: n/a
 
      05-04-2004
> 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


 
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
Can XSLT render the content: &lt;p&gt as html <p> rather than text? mark4asp XML 8 03-17-2008 11:54 AM
HyperLinkColumn - Button rather than text Iain ASP .Net 0 02-14-2007 10:07 AM
setting language/culture set the start of a page, rather than foreach date Kevin Blount ASP .Net 2 08-23-2006 08:29 PM
Dropdown control that displays images rather than text? Surendra ASP .Net Web Controls 1 04-05-2006 02:59 PM
ASP to display image rather than text path ?? david@scene-double.co.uk ASP General 2 08-16-2005 01:28 PM



Advertisments