Dropdownlist default value

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
 
I

Ivan

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
 
A

Aymer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,268
Messages
2,571,096
Members
48,773
Latest member
Kaybee

Latest Threads

Top