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

Add blank item to dropdown list in datagrid

P: n/a
I know it's been asked a million times before, but I still can't seem to
find an answer that works.

I've got a dropdown list in the footer template of a datagrid. The
dropdown list databinds, but I can't seem to add a blank item to the top
of the dropdown list.

I've tried using the code to add this by placing it in both the
page_load and the datagrid.itemDataBound event, but neither seems to
work. I've also referenced the control by
ctype(e.items.findControl("ddlName"), Dropdownlist) and by it's actual
id. I've tried both the .add and .insert method's of the
dropdownlist.items collection.

I've been able to get this to work outside of the datagrid, but can't
seem to get it to work inside the datagrid. Any help would be greatly
appreciated!!!

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Footer Then
'option 1 - doesn't work
CType(e.Item.FindControl("cmbAddFeatureType2"),
DropDownList).Items.Insert(0, New ListItem("Select", ""))
'option 2 - doesn't work
Me.cmbAddFeatureType2.Items.Insert(0, New ListItem("Select",
""))
End If
End Sub

Big Dave

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Big Dave,

If you want to add the item into the ddl inside the grid, you should use
PreRender event. But I don't think it's the best idea. You can achieve the
same effect by adding an empty row to the datatable the ddl is bound to.
That's what I am doing in my projects.

Eliyahu

"Big Dave" <pr******************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I know it's been asked a million times before, but I still can't seem to
find an answer that works.

I've got a dropdown list in the footer template of a datagrid. The
dropdown list databinds, but I can't seem to add a blank item to the top
of the dropdown list.

I've tried using the code to add this by placing it in both the
page_load and the datagrid.itemDataBound event, but neither seems to
work. I've also referenced the control by
ctype(e.items.findControl("ddlName"), Dropdownlist) and by it's actual
id. I've tried both the .add and .insert method's of the
dropdownlist.items collection.

I've been able to get this to work outside of the datagrid, but can't
seem to get it to work inside the datagrid. Any help would be greatly
appreciated!!!

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Footer Then
'option 1 - doesn't work
CType(e.Item.FindControl("cmbAddFeatureType2"),
DropDownList).Items.Insert(0, New ListItem("Select", ""))
'option 2 - doesn't work
Me.cmbAddFeatureType2.Items.Insert(0, New ListItem("Select",
""))
End If
End Sub

Big Dave

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

Nov 19 '05 #2

P: n/a
Okay, I tried this, it still didn't work.
Private Sub DataGrid1_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.PreRender
Me.cmbAddFeatureType2.Items.Insert(0, New ListItem("Select",
""))
End Sub

I also tried it on the dropdownlist's prerender event, and it didn't
work. It never even fired the event.

I'm pretty hesitant about adding a blank record to my database lookup
tables. I'm certainly no expert, but that just seems like a bad idea.
Adding a blank item to the dropdown seems like it should be easy, but I
just can't find a way to do it in the datagrid. So, I'm still looking
for help, thanks!!!

Big Dave

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

P: n/a
vlo
Does anyone know the answer to this other than adding a blank record? There has to be a way to acheive this! :(

From http://www.developmentnow.com/g/8_20...n-datagrid.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Jan 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.