Friday, March 16, 2012

Listbox default value

I have a listbox showing the values from a data base, but I'd like to include an extra field like "chose the value". The only way I know is creating a new field in the data base. There is another way?

Thanks

BriegaYes, there is another way. After the call to DataBind, given a listbox called lb:


lb.Items.Insert(0,"--Choose the Value--")

There is another overload of Items.Insert that will allow you to insert an item with a specified text and value, if that is required.
Hello,

sure there are another ways. You can insert a new row in a listbox or of course a dropdownlistbox with the methodsInsert orAdd like in the following examples:

myListbox.Items.Insert(0, New ListItem("NewText", "0"))
where the first parameter of ListItem is the text which appears and the second parameter is the value. In this case the 0 indicates that the item will be insert at the first postion. With theAdd-Method it is just possible to append items like in the following example:
myListbox.Items.Add("NewText")
HTH,
The sample inlink is for Dropdownlist
Changing it to listbox will do the work

0 comments:

Post a Comment