473,480 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do you find a control in the EditItemTemplate of a GridView?

I am using a GridView to display and edit rows of data. I am having
problems with one of my GridViews that has a Calendar control in it. If
the data coming back from the DB doesn't have a date for this field, I
get a 'Specified Cast is Invalid' message when the empty string is
being bound to the SelectedValue of the Calendar control. That makes
sense.

What I need to do (I think), is somehow intercept the process so that
if I have a DB date that is null, I can tell the Calendar control to
use it's default value of '1/1/0001 12:00:00 AM' for the SelectedValue
property when going into edit mode.

In the RowEditing event I was able to determine that the Label control
(ItemTemplate) for the date column was an empty string. I did this
using FindControl, but I cannot seem to figure out how to find the
Calendar control (EditItemTemplate) so that I can tell it to use the
default date instead of trying to bind the empty string.

Any ideas?

Jul 31 '06 #1
2 8454
I would try to put something in the RowDataBound event handler of the GridView

"Sean" wrote:
I am using a GridView to display and edit rows of data. I am having
problems with one of my GridViews that has a Calendar control in it. If
the data coming back from the DB doesn't have a date for this field, I
get a 'Specified Cast is Invalid' message when the empty string is
being bound to the SelectedValue of the Calendar control. That makes
sense.

What I need to do (I think), is somehow intercept the process so that
if I have a DB date that is null, I can tell the Calendar control to
use it's default value of '1/1/0001 12:00:00 AM' for the SelectedValue
property when going into edit mode.

In the RowEditing event I was able to determine that the Label control
(ItemTemplate) for the date column was an empty string. I did this
using FindControl, but I cannot seem to figure out how to find the
Calendar control (EditItemTemplate) so that I can tell it to use the
default date instead of trying to bind the empty string.

Any ideas?

Aug 1 '06 #2

For those interested, I finally have a solution. A colleague of mine
helped me out with some ideas. The problem was the <%#
Bind("dateColumn") %statement on SelectedValue property of the
Calendar control that I had defined in my EditItemTemplate. I needed to
intercept the NULL date value at that point in order to handle things
in the code behind.

Instead of doing two way data binding, I inserted a call to a protected
function in the code behind, where I was doing the bind. ( ex: <%#
GetDateValue( "dateColumn" ) %). In that function I would determine
if I had a NULL date and set an internal date variable to
DateTime.MinValue and return it to the Calendar control so it would
display and not give me the Cast invalid error message.

Because I was no longer doing two way data binding I now had to handle
getting any new date value the user might have selected for sending
back in an update operation.

In the GridView RowUpdating event I used FindControl to get a reference
to the Calendar control, so that I could grab the SelectedDate value
and store it back into my internal DateTime variable. Now that I had
the new value stored off, I then was able to use the ObjectDataSource
Updating event to insert into the InputParameters collection the value
stored in my internal DateTime variable.

All is well!

Aug 1 '06 #3

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

Similar topics

4
5334
by: GregG | last post by:
Greetings, I have been working with the new GridView control, and while figuring out most of it's idiosyncrasies on my own, have stumbled upon a problem I cannot seem to resolve. We have...
3
17072
by: Dabbler | last post by:
I have a checkbox control in a GridView EditItemTemplate. My SqlDataAdapter complains when I try and use UpdateCommand Thanks on any binding clarification. GridView: <asp:TemplateField...
2
2533
by: bpd | last post by:
I have a user control embedded in a gridview as an EditItemTemplate. When updating, the value is not saved to the database. I have an SQLDataSource attached to the Gridview. Can someone point me...
0
1463
by: aitor.diazdealda | last post by:
I am in a very deep hole and i can not see the light . Here my mistake if you could help me. store procedure.-they work ok. ALTER PROCEDURE dbo.UpdateEtiClientesEtidora ( @CLI_COD_PLAZA...
0
1120
by: dch | last post by:
I have a GridView, and when I click Edit, it is firing the OnRowEditing event ,and I am setting the edititem index, but it keeps displaying the ItemTemplate fields instead of the EditItemTemplate. I...
2
2466
by: Danielle | last post by:
Hello all - Thank you in advance for any help you are able to provide. I am populating a gridview from a stored procuedure. The returned data is a name, phone number, email and guid of a...
2
1411
by: Knoxy | last post by:
Hi guys, I'm using a gridview to do some inline editing. The data binds okay, its goes into edit mode and cancel okay. I'm using my own custom commandName, "save", and it picks this up okay. Don't...
3
2022
by: kimbred | last post by:
Can someone help? I have the code below in which I'm attempting to show or hide the edit control in a gridview based on the value of a column in that view. It doesn't seem to find the control. ...
0
4160
parshupooja
by: parshupooja | last post by:
Hey All, I have where I want to do some manipulations and show in other column but unable to find their values in RowDatabound event even though I have two records in gridview <asp:GridView...
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
6737
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4776
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.