tags:

views:

34

answers:

1

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!

+1  A: 

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.

Leniel Macaferi
Well this solution can resolve this problem, but I really want other developers in this team to write "beautiful codes". Concatenating the values into one string is not so artistic, isn't it?
Danny Chen
ah ha~ finally we have the same solution :)
Danny Chen