Dropdownlist default value

  • Thread starter Thread starter Aymer
  • Start date Start date
A

Aymer

Scenario: i have a drop down list control in my form. i
am binding it with a dataset. that dataset contains the
value 1, 2, 3, ..., 10. so when the dropdownlist control
is loaded, it contain the values 1, 2, 3, ..., 10.

Problem: How do i create a default value for the
dropdownlist? After the dropdownlist control is loaded
and binded, i want the value to be "Select A Value", 1, 2,
3, ..., 10. I want to add "Select A value" in the
dropdownlist.

P.S. I am populating the dataset through a datareader
from a database call.

thanx for your help,
aymer
aymerb[@].yahoo.com
 
Hi,
This should work


Dim Item As ListItem = new ListItem()
Item.Text = "Select A Value"
Item.Value = 0
Item.Selected = True
MyDropDownList.Items.Add(Item)

Regards,
Ivan Zashev
 
ur idea works, but it places the new item at the bottom of
the dropdownlist. i change some things a little a bit so
the new item is on the top.

Dim Item As ListItem = New ListItem
Item.Text = "New"
Item.Value = "0"
Item.Selected = True
MyDropDownList.Items.Insert(0, Item)

thanx for your help,
aymer
aymerb[@].yahoo.com
 
Back
Top