vdevine15
asked on
Telerik RadGrid Custom Edit Form With Date Picker
I have a custom edit form in a Telerik RadGrid where I'm trying to get the dates to bind to the RadDatePicker controls. The problem is, when I bind the date to the control, it will not allow the form to show on insert because there is no date to bind on a new insert. I have tried binding in the code behind and also in the main page using "Container is GridEditFormInsertItem" but I keep getting "Object reference not set to an instance of an object".
Any help would be appreciated.
Any help would be appreciated.
<telerik:RadDatePicker ID="itemLastPurchaseRadDatePicker" runat="server" Width="150px"
Culture="en-US" DateFormat="M/d/yyyy" DisplayDateFormat="M/d/yyyy" ShowPopupOnFocus="true"
SelectedDate='<%# ((Container is GridEditFormInsertItem) ? false : Bind ("ItemVendorLastPriceDate")) %>'>
</telerik:RadDatePicker>
I tried this in the code behind as a separate try to no avail.
Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) Then
Dim editFormItem As GridEditFormItem = CType(e.Item, GridEditFormItem)
Dim parentItem As GridDataItem = editFormItem.ParentItem
Dim dateVendorLastPurchaseDate As RadDatePicker = CType(editFormItem.FindControl("itemLastPurchaseRadDatePicker"), RadDatePicker)
Dim lastPurchaseDate As String = parentItem("ItemVendorLastPriceDate").Text
If lastPurchaseDate <> "" Or lastPurchaseDate IsNot Nothing Then
dateVendorLastPurchaseDate.SelectedDate = lastPurchaseDate
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So on my ItemDataBound event for the insert, what when I use a Try/Catch is:
System.NullReferenceExcept ion: Object reference not set to an instance of an object. at DesktopModules_Inventory_i nventoryMa in.RadGrid 1_ItemData Bound(Obje ct sender, GridItemEventArgs e)
System.NullReferenceExcept
ASKER
I got it! I just added "And RadGrid1.MasterTableView.I sItemInser ted = False" to my If statement on the ItemDataBound and it all worked like a charm! Thanks for the feedback and thanks to the moderators for helping me reclassify this!
ASKER
You were the only one to respond, so you get the points anyway, thank you!
ASKER