This is a migrated thread and some comments may be shown as answers.

Setting SelectedDate In Edit Mode via CodeBehind

1 Answer 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 23 Apr 2009, 11:25 PM
I have a grid that displays its details in a Nested FormView.  When in EditMode I am trying to set a RadDateTimePIcket selecteddate property to the database column IF it has one.  Some have no value so I want it to default to Now() or NOTHING.

I am getting a "Object reference not set to an instance of an object." error when trying to do it like this:

ElseIf (e.CommandName = "Edit"Then 
 
            Dim Event_Control As RadDateTimePicker = form_AppNotes.Row.FindControl("txt_event_date"
 
 -->Dim Event_Date As String = (TryCast(form_AppNotes.Row.FindControl("txt_event_date"), RadDateTimePicker)).SelectedDate.ToString 
 
            Event_Control.SelectedDate = IIf(GenericFunctions.DoIExist(Event_Date) = False, Now, FormatDateTime(Event_Date)) 
 
        End If 

It does not like the line I arrowed to above.  What am I missing here?!?

<telerik:RadDateTimePicker ID="txt_event_date" Runat="server" Skin="Sunset" SelectedDate='<%# Bind("event_date") %>'

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 24 Apr 2009, 04:40 AM
Hello Shawn,

You can access the RadDatePicker from the Edit From Template in the ItemDataBound using the following code:

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) 
    If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then 
        Dim editItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem) 
 
        Dim Event_Control As RadDatePicker = DirectCast(editItem.FindControl("txt_event_date"), RadDatePicker) 
    End If 
End Sub 

Also refer to the following documents:
Referencing controls in grid row/edit form

Thanks
Princy.
Tags
Grid
Asked by
Shawn
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or