473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Add blank item to dropdown list in datagrid

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
3 7289
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: localhost | last post by:
A DataGrid with shows a label in one of the columns when in view mode. When in edit mode, I want to show a dropdown, and have the default selection set to what the textbox used to be. Right now...
5
by: Kris Rockwell | last post by:
Hello (again), I have gotten the dropdown list functionality to work through a few tricks (probably not the most efficient, but it works) but I am not sure how to set the default selected value....
0
by: Tim::.. | last post by:
Hi, I'm trying to create a function that will show the current value of a datagrid when you go into the edit mode of the datagrid. At the moment when ever I hit edit it just shows me a list of...
3
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
2
by: drdave | last post by:
All is working well for my dropdown/datagrid except I cannot figure out how to set my ddl selected index when the value is blank/null. ie before edit mode the lblVariation text value is blank.....
5
by: Steve B. | last post by:
Without adding whitespace to the ComboBox datasource is there a way I can add a blank entry or, a reset entry, to the ComboBox dropdown Thanks Steve
0
by: koti | last post by:
hi i have written some code for selecting an item in combobox dropdown list which is in datagrid columm. by scrolling the mouse we select any item from the list. but by pressing the down key...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.