Plotter
Plotter

Reputation: 39

Getting the value selected from drop down list into a string variable c#

static public String Titl;    

Now in simple programming language suppose i got a dropdown list on my form. when i debugged i found out that dropdowlist with the id dropdownlist1 when written

dropdownlist1.text; 

contains the value i selected in the dropdown menu. However when i did something like this:

titl = dropdownlist1.text;    

i was not getting the value in the titl variable. Help needed. Thank You!

Upvotes: 1

Views: 27566

Answers (4)

Nikhil D
Nikhil D

Reputation: 2509

int selectedIndex=dropdownlist1.SelectedIndex;//get index
string selectedText=dropdownlist1.SelectedItem.Text;//get text
string selectedValue=dropdownlist1.SelectedItem.Value;//get value

Upvotes: 1

Plotter
Plotter

Reputation: 39

 Titl = dropdownlist1.SelectedValue;

Works! Thank You!

Upvotes: 0

Vinoth
Vinoth

Reputation: 2439

 Title = !string.IsNullorEmpty(dropdownlist1.SelectedItem.Text) ?
 dropdownlist1.SelectedITem.Text : "";

Upvotes: 0

user1102001
user1102001

Reputation: 707

check this if you want text..then

 title=dropdownlist1.selecteditem.text;

and if you want value then

  title=dropdownlist1.selecteditem.value;

Upvotes: 3

Related Questions