putting 'Select Item' in a dropdownlist in vb.net 2003

vb.net 2003 ,  I am populating a dropdown list from my sql server.  When I run my web page, it will list the first item, I prefer to have some text in there like 'Select Item',  how would I put some generic text in the dropdownlist while pulling the items from sql server?    
Who is Participating?
TimCotteeConnect With a Mentor Head of Software ServicesCommented:
When you have bound the results from the query to the dropdown.

MyDropDownList.Items.Insert(0,New ListItem("Select Item",-1))

To add an item at the top of the list. If you prefer a different value to "-1" then change it accordingly.
After you have bound the dropdown list to the data, try this to insert at top.........
ddl.Items.Insert(0, New ListItem("Select.....", ""))
When you postback, you'll have to now validate the value of the drop down list, confirming that it isn't blank.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

bergertimeAuthor Commented:
Works great, but.......say the user has selected value 4, now in the ddl I have  "Item"  as my top item, can I prevent the user from selecting it?  Would I put an if statement in the value change event to prevent it?  I understand most of my users will see "Item" and want to click on it instead of all the listed items.  Thanks
first of all I am not sure you understand that the items.insert statement has to be within a check for postback
if not ispostback() then
  ddl.Items.Insert(0, "Select")
end if
If you knew that, please ignore my comment ..

>>Would I put an if statement in the value change event to prevent it?
is the dropdown a required field .. if yes add a required field validator with "initialvalue" property of the validator set as "Select"
else if this is not a required field validator, you will have to use a custom validator which will check if the selected value = "select"

there are other fancy ways of making the user not able to able to choose "select" using javascript onblur client side event and checking if vlaue = "select", then change it back to some other value ..

You can view in this way to bind you dropdownlist.So that your selected value will be "Select" at first.
ds is the DataSet from database.                  
DataView dvList;
DataRowView drv;
dvList = new DataView(ds.Tables[0]);
dd.DataSource = dvList;
drv = dvListDist.AddNew();
drv["one"] = "Select";
drv["two"] = "0";                        
dd.DataTextField = "one";
dd.DataValueField = "two";
dd.Selectedvalue = ds.Tables[0].Rows.Count-1;
Trying to see the difference between the accepted answer and mine..................... Nope think they're identical!! :-S
bergertimeAuthor Commented:
You are correct, I was in a hurrry to clean up any open questions I had, is there any way I can make it up to you?
Nah, don't worry. Was just curious why :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.