Hello,
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" <BR>AllowMultiRowSelection="false" CssClass="MyRadGrid" AllowAutomaticUpdates="false"> <BR><MasterTableView AllowSorting="False" AllowPaging="false" DataKeyNames="BanquetSiteId" <BR>TableLayout="Fixed" ClientDataKeyNames="BanquetSiteId" EditMode="EditForms"> <BR><NoRecordsTemplate> <BR><asp:Label runat="server" CssClass="AlignCenter" ID="lblNoRecords" ResourceKey="lblNoRecords" <BR>Width="100%" align="center" /> <BR></NoRecordsTemplate> <BR><Columns> <BR><telerik:GridBoundColumn DataField="SiteId" HeaderText="SiteId" Visible="false"> <BR></telerik:GridBoundColumn> <BR><telerik:GridTemplateColumn HeaderText="SiteName" HeaderStyle-HorizontalAlign="Left"> <BR><ItemTemplate> <BR><asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# getSiteUrl(Eval("SiteAlias"))%>' <BR>Text='<%# Eval("SiteName")%>' Target="Blank"></asp:HyperLink> <BR></ItemTemplate> <BR></telerik:GridTemplateColumn> <BR><telerik:GridBoundColumn DataField="ExpireDate" HeaderText="ExpireDate" HeaderStyle-HorizontalAlign="Left"> <BR></telerik:GridBoundColumn> <BR><telerik:GridCheckBoxColumn DataField="IsActive" HeaderText="IsActive" HeaderStyle-HorizontalAlign="Left"> <BR></telerik:GridCheckBoxColumn> <BR><telerik:GridEditCommandColumn ButtonType="LinkButton"> <BR></telerik:GridEditCommandColumn> <BR></Columns> <BR><EditFormSettings EditFormType="Template"> <BR><FormTemplate> <BR><table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" <BR>style="border-collapse: collapse; background: white;"> <BR><tr class="EditFormHeader"> <BR><td colspan="2" style="font-size: small"> <BR><b>Subscription Details</b> <BR></td> <BR></tr> <BR><tr> <BR><td> <BR><asp:Label ID="Label2" ResourceKey="litExpireDate" runat="server">Expire Date</asp:Label> <BR></td> <BR><td> <BR><telerik:RadDatePicker ID="rdpExpireDate" runat="server" ValidationGroup="BanquetSite" /> <BR></td> <BR></tr> <BR><tr> <BR><td> <BR></td> <BR><td> <BR><asp:CheckBox ID="chkIsActive" Text="IsActive" ResourceKey="IsActive" Checked='<%# Bind( "IsActive" ) %>' runat="server" /> <BR></td> <BR></tr> <BR><tr> <BR><td align="right" colspan="2"> <BR><asp:Button ID="btnUpdate" Text="Update" runat="server" CommandName="Update"></asp:Button> <BR><asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button> <BR></td> <BR></tr> <BR></table> <BR></FormTemplate> <BR></EditFormSettings> <BR></MasterTableView> <BR><ClientSettings EnablePostBackOnRowClick="false"> <BR><ClientEvents></ClientEvents> <BR><Selecting AllowRowSelect="true" /> <BR><Scrolling AllowScroll="true" UseStaticHeaders="True" SaveScrollPosition="True" /> <BR></ClientSettings> <BR><PagerStyle Mode="NextPrevAndNumeric" /> <BR></telerik:RadGrid>
Code behind:
===========
Private Sub grdSites_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grdSites.UpdateCommand Try 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 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) grdSites.EditIndexes.Clear() BindBanquetSites() Catch ex As Exception lblMessage.Text = ex.Message End Try End SubIn 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, though the control is coming up fine.
Any help would be highly appreciated.
Thanks
Tariq