By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,564 Members | 804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,564 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.