开发者

ASP.NET & C# - Two values in a listbox?

I'm adding ListItems to a ListBox from two controls, both are DropDownLists.

The ListItem has the properties ListItem.SelectedItem and ListItem.SelectedValue, but I also want the ListBox to keep track of wh开发者_开发问答ich DropDownList the ListItem came from.

What would be the best way to do this?


You could set the ID of the dropdown programatically as a attribute of the listitem.

ListItem i = new ListItem();
i.Attributes["IDofDropDown"] = "SomeID";


Encode the .Value section so that its something like DropDownList1:SomeValue and then you can use String.Split to extract the info back out of .SelectedValue?


ListItem item contains Text and Value properties that mapped from option element in HTML. So you can not add any other value to this structure. But maybe you can save the source dropdown's id to the Value of the ListItem.


You could create an in memory dataset to store all the data needed and then bind the dataset to your ListBox. When ever a value is selected you will have access to more fields in code behind.


The way I went about solving this, was creating an ArrayList, with another array inside for each item.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜