views:

263

answers:

4

I am using ASP.NET 3.5

I have a dropdownlist called lstCountry with an item in it like this.....

<asp:ListItem Value="United States">Canada</asp:ListItem>

This will display Canada but in code the value will be "United States". How can i retrieve the value "Canada" also in my code?

I have tried all of these and all of them return "United States"

lstCountry.Text
lstCountry.SelectedValue
lstCountry.SelectedItem.Text

Thanks in advanced!

EDIT: More code

My Drop Down list

 <asp:DropDownList ID="lstCountry" runat="server" Width="200px">
              <asp:ListItem>Please Select</asp:ListItem>
  <asp:ListItem>United States</asp:ListItem>
  <asp:ListItem Value="United States">Canada</asp:ListItem>
 </asp:DropDownList>

How i read the value in code

    Dim country As String
    country = lstCountry.SelectedItem.Text
A: 

try

lstCountry.SelectedItem.Text
ArsenMkrt
Nope, this is also returning the value "United States"
Etienne
please provide more code please, I guess you are doing something wrong in other places
ArsenMkrt
A: 

You can try

lstCountry.SelectedItem.Text
Himadri
Nope, this is also returning the value "United States"
Etienne
+1  A: 

add list using

<asp:ListItem Value="United States" Text="Canada"></asp:ListItem>

and then try

DropDownList1.SelectedItem.Text

I found your mistake.

<asp:ListItem>United States</asp:ListItem>

change this to

<asp:ListItem>United States1</asp:ListItem>

Then you will got the actual value.

What was the issue is, there are two same values in your dropdown, when page postback, it take first value as selected and give the result accordingly. if you noticed when after postback United State Value is selected

Muhammad Akhtar
Nope, this is also returning the value "United States"
Etienne
then there must be some other issue in your dropdown
Muhammad Akhtar
are you setting selectedIndex=1 somewhere?
Muhammad Akhtar
@Muhammad....nope not at all......
Etienne
Nope it is not that, I have ALOT more items in my list. If i select one down below where the text and value is the same it is not returning United States.
Etienne
I also opened a BLANK page and tested the code....its not working for me.
Etienne
Could you send that Blank page in my email @ [email protected]
Muhammad Akhtar
A: 

What about

lstCountry.Items[lstCountry.SelectedIndex].Text;
rahul
Nope, this is also returning the value "United States"
Etienne