|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Drop down listbox - extra properties, possible?I am constantly dealing with situations whereby it would be nice to have, say, a couple more values embedded in a listbox, that would be nice and easy to retrieve in code. i.e. like this: ---------------------------------------------------- Dim li = New ListItem li.text = "Pounds Sterling" li.value = "1" li.value2 = "100" 'Note Value2 is not a real property ddlTest.Items.Add(li) li.text = "Dollars" li.value = "2" li.value2 = "135" 'Note Value2 is not a real property ddlTest.Items.Add(li) End Sub ---------------------------------------------------- So when the user select the listbox, not only can I access ddlTest.SelectedItem and ddlTest.Selectedvalue, but I could also have ddlTest.Selectedvalue2 I'm always having to write code around listboxes, and generally I end up putting a few overflow values in a viewstate array, which can get very messy having to iterate through this sort of code. I am wondering, how would you go about adding an extra value property to the base class of a listbox, be able to retrieve this value, and still be able to drag a ddlistbox onto the form in VS2003. How simple would this be to achieve? Has anybody achieved it? Any examples or comments? Cheers Alex Hello,
You could try and extend the ListItem class and add your extra properties. Say you create a class: class ListItem2 : ListItem { ... } Then when you use it: ListItem2 li2 = new ListItem2(); .... ddlTest.Items.Add((ListItem)li2); When you retrieve it: ListItem2 li2_copy = (ListItem2)ddlTest.Items[0]; I have not tested this code, but you should get the idea from it. Regards, -Visar Show quoteHide quote "posti***@alexshirley.com" wrote: > Hi > > I am constantly dealing with situations whereby it would be nice to > have, say, a couple more values embedded in a listbox, that would be > nice and easy to retrieve in code. > > i.e. like this: > > ---------------------------------------------------- > > Dim li = New ListItem > li.text = "Pounds Sterling" > li.value = "1" > li.value2 = "100" 'Note Value2 is not a real property > ddlTest.Items.Add(li) > li.text = "Dollars" > li.value = "2" > li.value2 = "135" 'Note Value2 is not a real property > ddlTest.Items.Add(li) > End Sub > > ---------------------------------------------------- > > So when the user select the listbox, not only can I access > ddlTest.SelectedItem and ddlTest.Selectedvalue, but I could also have > ddlTest.Selectedvalue2 > > I'm always having to write code around listboxes, and generally I end > up putting a few overflow values in a viewstate array, which can get > very messy having to iterate through this sort of code. > > I am wondering, how would you go about adding an extra value property > to the base class of a listbox, be able to retrieve this value, and > still be able to drag a ddlistbox onto the form in VS2003. > > How simple would this be to achieve? > Has anybody achieved it? > Any examples or comments? > > Cheers > > Alex > >
Other interesting topics
SRE (Simple Rule Engine)
Error: Cannot use a leading .. to exit above the top directory. DROPDOWNLIST SELECTEDINDEXCHANGED order of usercontrols processed by events of page how to capture click event in aspx from placeholder ->control Control opens over another How do I create an Unordered List (UL) with ASP.NET? ASP.NET Server Controls not displayed in IE How to diisable textbox in datagrid IHttpHandler persistence |
|||||||||||||||||||||||