i’ve populated a dropdownlist control with different text properties but each text properties had THE SAME value (text property was A, value properties is blah,text property was B, value properties is blahblah, etc… )
ASP.net only checks value properties on postback and because ALL values were the same (for testing reason) this little annoying behavior happened. Is there a work around? does this mean you can’t never have the value to be the same?
Sounds like you are working on the wrong event. Try SelectedIndexChanged.
Ensure you also have the
AutoPostBackproperty set toTrue.Resolved
OK, so I got digging on this since I was curious 🙂
There is a "problem" when databinding with non-unique values.
So, firstly, I publicly apologise for saying otherwise.
To replicate:
ASPX
Code-Behind
Run, changing the values in the DropDownList. Note that a PostBack does not occur.
When looking at the Source, I realised that we need to explicitly set the "
value" attribute for the<option>elements generated by the server control, which lead me to do something like:New Code-Behind
This explcitly sets the values to the "1", "2", "3" etc making them unique, while still displaying the correct data within the list.
Obviously, you can change this to work with single-column lists but just running through a for loop and using the value of
ior something.As to good workarounds with DataSets, not sure.
Realistically, would we present a list of options with the exact same values to the user?
I personally think not, which is probably why this "problem" hasn’t been addressed 🙂
Enjoy!
PS:
Oh, I should also add, if you want to use the text value in the "fix" then change it to
SelectedItemrather thanSelectedValue.