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

Unable to fetch the Grid's control values in Edit mode within UpdateCommand

1 Answer 63 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 03 Nov 2010, 08:04 AM

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>&nbsp; <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 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, though the control is coming up fine.

Any help would be highly appreciated.

Thanks
Tariq

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 08 Nov 2010, 09:55 AM
Hi Tariq,

In order to be able to retrieve the values of the mentioned controls, you need to use two-way declarative binding to bind them in the first place. Then the code you have in the UpdateCommand should be working as expected.

Additionally, you can check out this online demo for more information on RadDatePicker data-binding.

All the best,
Iana
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
Iana Tsolova
Telerik team
Share this question
or