By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,649 Members | 2,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,649 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.It em
("Display_Name").ToString()
cboDeliveryDateType.DataValueField =
oDsDeliveryDateType.Tables("DataTable").Columns.It em
("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...
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
--
Elliot M. Rodriguez, MCSD
*** It would take 227 cans of Mountain Dew to kill me***

"Chris" <ch****@papex.com> wrote in message
news:80****************************@phx.gbl...
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.It em
("Display_Name").ToString()
cboDeliveryDateType.DataValueField =
oDsDeliveryDateType.Tables("DataTable").Columns.It em
("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...

Nov 17 '05 #2

P: n/a
Elliot,

Dead on. Thank you. Problem solved.

Thanks,

Chris...

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.