Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Add blank item to dropdown list in datagrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Big Dave - 18 Jan 2005 13:59 GMT
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
Eliyahu Goldin - 18 Jan 2005 14:37 GMT
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

> I know it's been asked a million times before, but I still can't seem to
> find an answer that works.
[quoted text clipped - 31 lines]
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Big Dave - 18 Jan 2005 15:11 GMT
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
vlo - 22 Jan 2006 22:33 GMT
Does anyone know the answer to this other than adding a blank record? There has to be a way to acheive this! :(
Tomas - 02 Aug 2007 15:23 GMT
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/2007/08/dropdownlist-with-blank-item-on-top.htm

From http://www.developmentnow.com/g/8_2005_1_0_0_40155/Add-blank-item-to-dropdown-li
st-in-datagrid.ht


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.