Reputation: 43531
Currently in asp.net, we can have only one value in a ListItem in a DropDownList. However I hope I can:
<MultiValueDropDownList id="ddl" runat="server" />
ddl.Items.Add(new MultiValueListItem { Text="text", DBValue="db", EngineValue=1 });
var dbValue = ddl.SelectedItem.DBValue;
What I'm going to do is inherit DropDownList and ListItem. Do you guys have any better solutions?
[Closed]
At last I decide to choose a lazy way. Store the values in ListItem.Attributes
. And using extension methods of DropDownList to help to get the collection of values. Thanks for your help!
Upvotes: 3
Views: 2876
Reputation: 102448
See if this helps:
How to display multi-column in ASP Dropdown List?
Edit:
You can not inherit from ListItem
.
See why: Extending ASP.NET DropDownList
The best solution then is to store the values inside ListItem.Attributes
.
Upvotes: 1