Adding a list item to the System.Web.UI.WebControls.DropDownList

C

Chris

I was wondering if there was any way to add a blank list
item control to the beginning of the
System.Web.UI.WebControls.DropDownList's datasource after
the control's datasource has been specified.

Here's my code right now:

Dim oEmptyOption as New ListItem()

'Assign datasource to delivery date type combobox
cboDeliveryDateType.DataSource = oDsDeliveryDateType.Tables
("DataTable")
cboDeliveryDateType.DataTextField =
oDsDeliveryDateType.Tables("DataTable").Columns.Item
("Display_Name").ToString()
cboDeliveryDateType.DataValueField =
oDsDeliveryDateType.Tables("DataTable").Columns.Item
("Delivery_Date_Type_ID").ToString()
cboDeliveryDateType.DataBind()

'Add empty option field
cboDeliveryDateType.Items.Add(oEmptyOption) 'adds to the
end of the list.

Currently, I am able to add the blank item at the end of
the controls Item's list, and select it as the default
selected item, but it appears as the last item in the drop
down list. I want to have it at the beginning of the list.
Any suggestions would be greatly appreciated.

Thanks,

Chris...
 
E

Elliot M. Rodriguez

Chris:

Try using Insert instead of Add - it takes the index to add the ListItem to,
and the ListItem object you want to add:

cboDeliveryDateType.Items.Insert(0, oEmptyOption)

HTH
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top