Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grabbing values from a dropdown list

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
If I have a dropdown list like this below, where 0,1,2,3, ect are the index numbers. Say I have selected index 2. How would I store the text in index 1 in a variable? so if I select 2005. I want to store 2004 in a variable.

0 - 2003
1 - 2004
2 - 2005
3 - 2006
 
ddl_whatever.SelectedItem.Value for the value...
ddl_whatever.SelectedItem.Value for the text...
 
sorry ddl_whatever.SelectedItem.Text for the text... typed too quickly...


and then you can store these in whatever variable you choose....
Session variable...
c#

Session["employee_no"]=ddl_employees.SelectedItem.Value;
Session["employee_nm"]=ddl_employees.SelectedItem.Text;

 
this would grab the current selected text, not the text in the position above the selected text.
 
sorry was a bit confused
then do a ddl_whatever.items.findbyvalue(ddl_whatever.SelectedItem.Value) to determine the selectedindex of the current item subtract one- ensure you are within the valid range >=0 and <=number of items in the dropdownlist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top