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

Unable to fetch raddatepicker selecteddate from radgrid within its UpdateCommand

1 Answer 93 Views
This is a migrated thread and some comments may be shown as answers.
Tariq H
Top achievements
Rank 1
Tariq H asked on 02 Nov 2010, 01:54 PM


I am using the following code to generate a grid for displaying and editing some data.

Unfortunately I am not able to get the value of the raddatepicker & the checkbox control in code behind to update the associated fields in the DB.

My aspx is as follows:



telerik:RadGrid ID="grdSites" runat="server" AllowAutomaticDeletes="false" AutoGenerateColumns="False"












AllowMultiRowSelection="false" CssClass="MyRadGrid" AllowAutomaticUpdates="false">










<MasterTableView AllowSorting="False" AllowPaging="false" DataKeyNames="BanquetSiteId"










TableLayout="Fixed" ClientDataKeyNames="BanquetSiteId" EditMode="EditForms">




















<asp:Label runat="server" CssClass="AlignCenter" ID="lblNoRecords" ResourceKey="lblNoRecords"










Width="100%" align="center" />






























<telerik:GridBoundColumn DataField="SiteId" HeaderText="SiteId" Visible="false">




















<telerik:GridTemplateColumn HeaderText="SiteName" HeaderStyle-HorizontalAlign="Left">




















<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# getSiteUrl(Eval("SiteAlias"))%>'










Text='<%# Eval("SiteName")%>' Target="Blank"></asp:HyperLink>






























<telerik:GridBoundColumn DataField="ExpireDate" HeaderText="ExpireDate" HeaderStyle-HorizontalAlign="Left">




















<telerik:GridCheckBoxColumn DataField="IsActive" HeaderText="IsActive" HeaderStyle-HorizontalAlign="Left">




















<telerik:GridEditCommandColumn ButtonType="LinkButton">






























<EditFormSettings EditFormType="Template">




















<table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"










style="border-collapse: collapse; background: white;">










<tr class="EditFormHeader">










<td colspan="2" style="font-size: small">










<b>Subscription Details</b>


















































<asp:Label ID="Label2" ResourceKey="litExpireDate" runat="server">Expire Date</asp:Label>






























<telerik:RadDatePicker ID="rdpExpireDate" runat="server" ValidationGroup="BanquetSite" />






































































<asp:CheckBox ID="chkIsActive" Text="IsActive" ResourceKey="IsActive" Checked='<%# Bind( "IsActive" ) %>' runat="server" />








































<td align="right" colspan="2">










<asp:Button ID="btnUpdate" Text="Update" runat="server" CommandName="Update"></asp:Button>&nbsp;










<asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
















































































<ClientSettings EnablePostBackOnRowClick="false">




















<Selecting AllowRowSelect="true" />










<Scrolling AllowScroll="true" UseStaticHeaders="True" SaveScrollPosition="True" />




















<PagerStyle Mode="NextPrevAndNumeric" />
















Code behind:



Sub grdSites_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grdSites.UpdateCommand




Dim banquetSitId As Integer = CType(grdSites.MasterTableView.DataKeyValues(e.Item.ItemIndex).Values(0), Integer)

'Dim rdp As RadDatePicker


Dim expireDate As DateTime = Nothing


Dim isActive As Boolean


'If e.CommandName = RadGrid.UpdateCommandName Then

' If TypeOf (e.Item) Is GridEditFormItem Then


' Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)


' If DirectCast(item.FindControl("rdpExpireDate"), Telerik.Web.UI.RadDatePicker).SelectedDate.HasValue Then



' expireDate = CType(item.FindControl("rdpExpireDate"), Telerik.Web.UI.RadDatePicker).SelectedDate.Value


' End If


'End If


TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode AndAlso Not e.Item.OwnerTableView.IsItemInserted Then


'Dim editItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)


'Dim item As GridDataItem = DirectCast(editItem.ParentItem, GridDataItem)


'Dim datepick As RadDatePicker = DirectCast(editItem.FindControl("rdpExpireDate"), RadDatePicker)


Dim editedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)

Dim datepick As RadDatePicker = DirectCast(editedItem.FindControl("rdpExpireDate"), RadDatePicker)

expireDate = datepick.SelectedDate.Value


End If



If Not e.Item.FindControl("rdpExpireDate") Is Nothing Then  


If CType(e.Item.FindControl("rdpExpireDate"), Telerik.Web.UI.RadDatePicker).SelectedDate.HasValue Then

    expireDate =


CType(e.Item.FindControl("rdpExpireDate"), Telerik.Web.UI.RadDatePicker).SelectedDate.Value

End If  


End If





If Not e.Item.FindControl("chkIsActive") Is Nothing Then

    isActive = CType(e.Item.FindControl("chkIsActive"), CheckBox).Checked  

End If




BanquetController.UpdateBanquetSite(banquetSitId, expireDate, isActive)


lblMessage.Text = Localization.GetString(

"SubscribeSuccess.Text", Me.LocalResourceFile)





Catch ex As Exception  


lblMessage.Text = ex.Message



End Try



End Sub

In the above code "datepick.SelectedDate.Value" returns null for me.
I have tried out a number of other combinations(currently commented out) as well, all returning null for me.

Any help would be highly appreciated.





1 Answer, 1 is accepted

Sort by
Telerik team
answered on 05 Nov 2010, 10:32 AM
Hi Tariq,

Please, take a look at the instructions provided in this help article on how to correctly update values of a RadGrid using FormTemplate as an edit form.

the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Asked by
Tariq H
Top achievements
Rank 1
Answers by
Telerik team
Share this question