How to save a third value in each ListItem of an ASP.NET dropdownlist? -



How to save a third value in each ListItem of an ASP.NET dropdownlist? -

each listitem in asp.net has value property , text property. need have 3rd value saved also. hack concatenate special separator , 3rd value value property. using findbyvalue method makes cumbersome.

is there improve way save 3rd value or way utilize findbyvalue. (i can't utilize findbytext). wish there tag property.

if using binded dropdownlist, defined datatextfield , datavaluefield properties, there's not way save 3rd value on dropdownlist itself. save separately tho.

if you're defining dropdownlist through markup, seek defining custom attribute:

<asp:dropdownlist id="ddldummy" runat="server"> <asp:listitem text="x" value="y" thirdvalue="z" /> </asp:dropdownlist>

for retrieving it, utilize findbyvalue , thirdvalue attribute listitem:

listitem item = ddldummy.items.findbyvalue("y"); string value = item.attributes["thirdvalue"];

however, weirdly, if generate items dynamically, attributes not persisted:

protected void page_load(object sender, eventargs e) { if(!ispostback) { listitem item = new listitem("x", "y"); item.attributes.add("thirdvalue", "z"); ddldummy.items.add(item); } }

if case, take @ question gives work arround:

listitems attributes in dropdownlist lost on postback?

asp.net

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -