473,378 Members | 1,106 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,378 software developers and data experts.

How to initialize dropdownlist value in a gridview column edit template

I have dropdown list in a gridview column edit template. It works OK, except
when I edit a row, the dropdown list does not initialize to the existing
value that shows in the textbox that displays in the item template. I tried
to initialize the selected value of the dropdown list with some lines of
code in the grid_RowEditing event but I get an error that I do not
understand. The error occurs at this line of code:

String DelID =
((DropDownList)grid.Rows[e.NewEditIndex].FindControl("DelDropDownList")).Text;

the error is: "Object reference not set to an instance of an object."

I do not understand this, because code from the grid_RowUpdating event that
runs error-free is the same except that it uses e.RowIndex instead of
e.NewEditIndex and both indexes have the same value. Can someone shed some
light on this for me?

Thanks,

Keith

Jun 1 '06 #1
2 7765
I think (and someone please correct me if I'm wrong) but all of the
controls inside the edit item template are not created until the data
grid is bound. Also the OnRowEditing event fires before the
OnRowDataBound event. Therefore during the on row editing event the
drop down list (and anything else inside the edit item template)
doesn't exist yet.

The way I got it to work for me when I ran into this problem is to
initialize the selected value of the drop down list during the
OnRowDataBound event- not the OnRowEditing event.

Jun 1 '06 #2
The solution turned was simple: I just needed to bind the SelectedValue
property of the DropDownList to the related field in the GridView edit
template. Now that I have done that, everything works.

Thanks,

Keith

<Ma***********@gmail.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.com...
I think (and someone please correct me if I'm wrong) but all of the
controls inside the edit item template are not created until the data
grid is bound. Also the OnRowEditing event fires before the
OnRowDataBound event. Therefore during the on row editing event the
drop down list (and anything else inside the edit item template)
doesn't exist yet.

The way I got it to work for me when I ran into this problem is to
initialize the selected value of the drop down list during the
OnRowDataBound event- not the OnRowEditing event.

Jun 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: COHENMARVIN | last post by:
I'm leafing through a big book on asp.net, and I don't see any way to the following: 1. bind values and text to a dropdown 2. Also make the first line of the dropdown say something different. For...
0
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though...
4
by: P. Yanzick | last post by:
Hello, I've been playing with master/detail views as well as editing in the gridview, and I ran across a strange problem that I am not exactly sure where to go to try to solve. I have 2...
0
by: den 2005 | last post by:
Hi everybody, I created a Gridview with a TemplateField and there is Label control in ItemTemplate and a DropdownList control in EditItemTemplate, I was to displayed them ok when I click the...
7
by: AG | last post by:
Hi, ASP.NET 2.0 web app I have a GridView utilizing template columns and bound to an objectdatasource. In the edit template of one column there is a dropdownlist bound to another...
1
by: mitchman10 | last post by:
My Time table has TimeID,Employee,PayPeriod,ChargeCodeID,Hours My Chargecode table has ChargecodeID,c_Text I need an Editable datagrid that will show the TimeID,Employee,PayPeriod,C_Text in a...
0
by: lamolap | last post by:
i have 1 gridview , a dropdownlist inside a gridview and a commandfield of (edit, update and cancel) my gidview looks like this Edit Surname Initials ...
3
by: S_K | last post by:
I have a GridView that has a DropDownList in one of the columns. When I edit and update any row I would like to grab the SelectedValue of that DropDownList when I'm in the GridView_RowUpdating...
1
by: arunbojan | last post by:
Hi All, I have an editable datagrid with 10 columns, one of those is ddl column which I used for showing the status.... By default all the columns are readonly, when user clicks edit,...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.