c# - Cant get text of a DropDownList in code - can get value but not text -


I am using asp.net 3.5

I have a drop-down list that With an item called lstCountry it is like this:

  & lt; Asp: ListItem value = "United States" & gt; Canada & lt; / Asp: ListItem & gt;  

This will display Canada but the value in the code will be "United States" How can I get the value of "Canada" in my code?

I have tried all these and they all return "United States"

  lstCountry.Text lstCountry My drop down list:  
  & lt; ASP: Dropdown list id = "lstCountry" runat = "server" width =  

"200px" & gt; & Lt; Asp: ListItem & gt; Please select & lt; / Asp: ListItem & gt; & Lt; Asp: ListItem & gt; United States & lt; / Asp: ListItem & gt; & Lt; Asp: ListItem value = "United States" & gt; Canada & lt; / Asp: ListItem & gt; & Lt; / ASP: DropDownList & gt;

How do I read values ​​in the code:

string country = country as a low country. Selected Iteem.Text

  and asp Add list by using: listItem value = "United States" text = "". Canada "& gt; & lt; / ASP: ListItem>  

and try again

  DropDownList1.SelectedItem.Text  < / Pre> 

I found your fault.

& asp: ListItem> United States
< P> Change it to

  and asp: ListItem> United States 1  

then you have real Value.

What was the issue, your dropdown has two identical values, when a page postback, it first assumes selected and accordingly give results. You saw that postback after United State value when determined


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

kernel - How to create a "Block device" in Windows -