Adding Blank Selection To A DropDownList Control

Because when you databind the data to the control, all previous data gets wiped out, so you have to add the new item afterwards. Also, it will appear at the end of the list. I don’t know of a way around that.

This code adds and selects an empty list item:

nameList.DataSource = MyDataTable
nameList.DataTextField = "Name"
nameList.DataValueField = "ID"
nameList.Items.FindByText("").Selected = True

Tip Submitted By: David McCarter


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s