473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
4 1120
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
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
> 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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jm | last post by:
I have datagrid. On this datagrid there is a button and a dropdownlist. When I press the button, I want the selectedIndex of the dropdownlist. There is a button and a dropdownlist for each...
10
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
4
by: wolfgang wagner | last post by:
hi all! after successfully integrating a dropdownlist in my datagrid i have another problem: i cannot set the selected index of the dropdownlistbox. here is my code: hardware.aspx...
1
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
2
by: Steve Hershoff | last post by:
Hi everyone, I have a DataGrid with several TemplateColumns. One of these columns has an EditItemTemplate that contains an ASP.Net DropDownList. I'm catching this DropDownList's...
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
0
by: Moneypenny | last post by:
Hi there, I have a Gridview control which has a dropdownlist in every row. The dropdowns are populated dynamically from a database (so the content is different in each row. There is also a select...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.