Get attribute from DropdownList SelectedItem

dotnetnoob picture dotnetnoob · Feb 12, 2013 · Viewed 10.6k times · Source

I have a dropdownlist where I need to store more data than the standard list item allows. The approach I've taken is to add an attribute to each of the listitems.

I monitor for changes and can return the SelectedIndex, but I'm not sure how to get the attribute back from there, or whether there are any easier ways of achieving this.

Any ideas?

Answer

banana picture banana · Feb 12, 2013

Try this:

ddl.SelectedItem.Attributes["key"];