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 117 Views
Grid
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

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"

 

 

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

<NoRecordsTemplate>

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

</NoRecordsTemplate>

 

 

 

 

 

 

 

 

 

<Columns>

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

<ItemTemplate>

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

</ItemTemplate>

 

 

 

 

 

 

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

</telerik:GridCheckBoxColumn>

 

 

 

 

 

 

 

 

 

<telerik:GridEditCommandColumn ButtonType="LinkButton">

 

 

 

 

 

 

 

 

 

</telerik:GridEditCommandColumn>

 

 

 

 

 

 

 

 

 

</Columns>

 

 

 

 

 

 

 

 

 

<EditFormSettings EditFormType="Template">

 

 

 

 

 

 

 

 

 

<FormTemplate>

 

 

 

 

 

 

 

 

 

<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>

 

 

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

 

 

<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"

 

 

 

 

 

 

 

 

 

CommandName="Cancel"></asp:Button>

 

 

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

 

 

</table>

 

 

 

 

 

 

 

 

 

</FormTemplate>

 

 

 

 

 

 

 

 

 

</EditFormSettings>

 

 

 

 

 

 

 

 

 

</MasterTableView>

 

 

 

 

 

 

 

 

 

<ClientSettings EnablePostBackOnRowClick="false">

 

 

 

 

 

 

 

 

 

<ClientEvents></ClientEvents>

 

 

 

 

 

 

 

 

 

<Selecting AllowRowSelect="true" />

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

</ClientSettings>

 

 

 

 

 

 

 

 

 

<PagerStyle Mode="NextPrevAndNumeric" />

 

 

 

 

 

 

 

 

 

</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 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.

Thanks
Tariq

 

 

 

1 Answer, 1 is accepted

Sort by
0
Tsvetina
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.

Regards,
Tsvetina
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
Tags
Grid
Asked by
Tariq H
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or