Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Add blank item to dropdown list in datagrid

Reply
Thread Tools

Add blank item to dropdown list in datagrid

 
 
Big Dave
Guest
Posts: n/a
 
      01-18-2005
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!
 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      01-18-2005
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" <(E-Mail Removed)> wrote in message
news:%23wNd1XW$(E-Mail Removed)...
> 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!



 
Reply With Quote
 
 
 
 
Big Dave
Guest
Posts: n/a
 
      01-18-2005
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!
 
Reply With Quote
 
vlo
Guest
Posts: n/a
 
      01-22-2006
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
 
Reply With Quote
 
Tomas
Guest
Posts: n/a
 
      08-02-2007
You add an empty item with some sentinel value to the DDL in the declaration, and set the DDL's AppendDataBoundItems property to True.

See: http://personalinertia.blogspot.com/...tem-on-top.htm

From http://www.developmentnow.com/g/8_20...in-datagrid.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
possible to allow a user to type directly into a dropdown list to add new item? Dica ASP .Net 4 11-09-2005 02:43 PM
How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the datagrid Update event. Daniel Roth ASP .Net Datagrid Control 0 04-05-2005 03:58 AM
Setting background list item color in dropdown list control M. Craig ASP .Net Web Controls 1 01-09-2004 03:32 AM
How to set background color of List item in dropdown list M. Craig ASP .Net Web Controls 0 11-12-2003 06:26 PM



Advertisments