It looks like you are working on the wrong event. Try SelectedIndexChanged .
Verify that the AutoPostBack property AutoPostBack set to True .
Decided
OK, so I began to delve into this, as I was curious :)
There is a problem when binding data to non-standard values.
So, firstly, I publicly apologize for something else.
Repeat:
Aspx
<asp:DropDownList ID="myDDL" runat="server" AutoPostBack="True"> </asp:DropDownList> <asp:Label ID="lblSelItem" runat="server"Text="Currently Selected Item: 0"></asp:Label> <asp:Label ID="lblSelVal" runat="server" Text="Currently Selected Value: X"></asp:Label>
Code-behind
List<string> MyData() { List<string> rtn = new List<string>(); rtn.Add("I am the same value!"); rtn.Add("I am the same value!"); rtn.Add("I am the same value!"); rtn.Add("I am the same value!2"); return rtn; } protected void Page_Init() { if (!Page.IsPostBack) {
Run by changing the values ββin the DropDownList. Please note that PostBack does not occur.
When I looked at Source, I realized that we needed to explicitly set the " value " attribute for the <option> elements generated by the server control, which made me do something like:
New code behind
Dictionary<string, string> MyTwoColData() { Dictionary<string, string> rtn = new Dictionary<string, string>(); rtn.Add("1", "I am the same value!"); rtn.Add("2", "I am the same value!"); rtn.Add("3", "I am the same value!"); return rtn; } protected void Page_Init() { if (!Page.IsPostBack) {
This explicitly sets the values ββto "1", "2", "3", etc., making them unique, while preserving the correct data in the list.
Obviously, you can change this to work with single-column lists, but just do a for loop and use the value i or something like that.
As for the good workarounds with DataSets, not sure.
Actually, will we present a list of parameters with the same values ββfor the user?
I personally do not think that, probably, why this "problem" was not solved :)
Enjoy it!
PS:
Oh, I also have to add if you want to use the text value in "fix" and then change it to SelectedItem and not to SelectedValue .