I have a DropDownList
in which I add items as below:
var item= new ListItem("Texto do Item", "Valor do Item");
item.Attributes.Add("NomeAtributo", "ValorAtributo");
The DropDownList
is rendered on the screen with the attribute, so far legal. When I select an item in DropDownList
it triggers an event in code behind
, where I want to get the value of the attribute again, however when I run the code below it comes null
:
var meuAtributo = meuDropDownList.SelectedItem.Attributes["NomeAtributo"];
The Microsoft documentation is written in the description of WebControl.Attributes
:
Gets the collection of arbitrary attributes (for rendering only)
Translation:
Pega a coleção de atributos arbitrários (somente para renderização).
How do I get the attribute value of this DropDownList
in the OnSelectedIndexChanged
event?