Cheng Chen
Cheng Chen

Reputation: 43531

Multi-value dropdownlist

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

Answers (1)

Leniel Maccaferri
Leniel Maccaferri

Reputation: 102448

See if this helps:

EasyListBox

How to display multi-column in ASP Dropdown List?

asp.net : an alternative to multi-column DropDownList Gridview within dropdownlist / combobox (using the Ajax DropDownExtender)

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

Related Questions