I have a radgrid in batch edit mode. I have GridDateTimeColumn. How can i get the selected value for the raddatepicker control in batch edit mode. I would like to do this on code behind.
I have copied radgrid control and radgrid's itemdatabound event below.
But here is the part of the code behind code snippet with my problem.
Inside the Itemdatabound event, i have this code to find the datepicker control.
drVal("Expected_Date") is always dbnull. Why?
If drVal IsNot Nothing Then
Dim dtExpected As RadDatePicker = DirectCast(editedItem("Expected_Date").Controls(0), RadDatePicker)
If drVal("Expected_Date") IsNot Nothing Then
If Not String.IsNullOrEmpty(drVal("Expected_Date").ToString) Then
dtExpected.SelectedDate = drVal("Expected_Date")
End If
End If
End If
aspx page
========
<telerik:RadGrid ID="rgCriticalCaps" runat="server" CssClass="SubGridGeneral" Width="100%"
BorderStyle="Solid" BorderWidth="0px" AllowAutomaticUpdates="True"
AutoGenerateColumns="False" AllowPaging="false"
AllowMultiRowEdit="True">
<ClientSettings>
<ClientEvents OnBatchEditOpening="BatchEditOpening" />
</ClientSettings>
<MasterTableView EditMode="Batch" DataKeyNames="PK_OrgSubmission, CapabilityID">
<BatchEditingSettings EditType="Cell" />
<NoRecordsTemplate>
Test message
</NoRecordsTemplate>
<Columns>
<telerik:GridDropDownColumn UniqueName="Reason"
HeaderText="Reasons Not Met."
DropDownControlType="RadComboBox" AllowSorting="false" HeaderStyle-VerticalAlign="Top">
</telerik:GridDropDownColumn>
<telerik:GridDateTimeColumn DataField="Expected_Date" PickerType="DatePicker"
DataFormatString="{0:MM/dd/yyyy}" DataType="System.DateTime" HeaderText="Expected Date."
HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="13%" ItemStyle-HorizontalAlign="Left" UniqueName="Expected_Date" />
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
</MasterTableView>
<HeaderStyle CssClass="SubGridHeader" />
<ItemStyle CssClass="SubGridRows" />
<AlternatingItemStyle CssClass="SubGridAltRows" />
<FilterMenu EnableImageSprites="False">
</FilterMenu>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
</HeaderContextMenu>
</telerik:RadGrid>
Code behind
==========
Protected Sub rgCriticalCaps_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles rgCriticalCaps.ItemDataBound
If e.Item.ItemType = GridItemType.EditItem And e.Item.IsInEditMode Then
Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
Dim editMan As GridEditManager = editedItem.EditManager
Dim editor As GridDropDownListColumnEditor = TryCast(editMan.GetColumnEditor("Reason"), GridDropDownListColumnEditor)
Dim SqlBuilder As StringBuilder = New StringBuilder
SqlBuilder.Append("SELECT PK_PickList,DisplayValue FROM PickLists WHERE PK_PickListType IN (SELECT PK_PickListType FROM PickListTypes WHERE UsageField = 'Capabilities_Reason_NotMet') order by SortPos")
Dim gridSql As String = SqlBuilder.ToString()
Dim oReason As DataTable = New DataTable
oReason = odbutils.GetDataTable(gridSql)
Dim rComboBox As RadComboBox = editor.ComboBoxControl
rComboBox.DataSource = oReason
rComboBox.DataTextField = "DisplayValue"
rComboBox.DataValueField = "PK_PickList"
rComboBox.DataBind()
Dim drVal = DirectCast(e.Item.DataItem, DataRowView)
If drVal IsNot Nothing Then
editor.SelectedValue = drVal("Reason_not_met").ToString()
Dim dtExpected As RadDatePicker = DirectCast(editedItem("Expected_Date").Controls(0), RadDatePicker)
If drVal("Expected_Date") IsNot Nothing Then
If Not String.IsNullOrEmpty(drVal("Expected_Date").ToString) Then
dtExpected.SelectedDate = drVal("Expected_Date")
End If
End If
End If
End If
I have copied radgrid control and radgrid's itemdatabound event below.
But here is the part of the code behind code snippet with my problem.
Inside the Itemdatabound event, i have this code to find the datepicker control.
drVal("Expected_Date") is always dbnull. Why?
If drVal IsNot Nothing Then
Dim dtExpected As RadDatePicker = DirectCast(editedItem("Expected_Date").Controls(0), RadDatePicker)
If drVal("Expected_Date") IsNot Nothing Then
If Not String.IsNullOrEmpty(drVal("Expected_Date").ToString) Then
dtExpected.SelectedDate = drVal("Expected_Date")
End If
End If
End If
aspx page
========
<telerik:RadGrid ID="rgCriticalCaps" runat="server" CssClass="SubGridGeneral" Width="100%"
BorderStyle="Solid" BorderWidth="0px" AllowAutomaticUpdates="True"
AutoGenerateColumns="False" AllowPaging="false"
AllowMultiRowEdit="True">
<ClientSettings>
<ClientEvents OnBatchEditOpening="BatchEditOpening" />
</ClientSettings>
<MasterTableView EditMode="Batch" DataKeyNames="PK_OrgSubmission, CapabilityID">
<BatchEditingSettings EditType="Cell" />
<NoRecordsTemplate>
Test message
</NoRecordsTemplate>
<Columns>
<telerik:GridDropDownColumn UniqueName="Reason"
HeaderText="Reasons Not Met."
DropDownControlType="RadComboBox" AllowSorting="false" HeaderStyle-VerticalAlign="Top">
</telerik:GridDropDownColumn>
<telerik:GridDateTimeColumn DataField="Expected_Date" PickerType="DatePicker"
DataFormatString="{0:MM/dd/yyyy}" DataType="System.DateTime" HeaderText="Expected Date."
HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="13%" ItemStyle-HorizontalAlign="Left" UniqueName="Expected_Date" />
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
</MasterTableView>
<HeaderStyle CssClass="SubGridHeader" />
<ItemStyle CssClass="SubGridRows" />
<AlternatingItemStyle CssClass="SubGridAltRows" />
<FilterMenu EnableImageSprites="False">
</FilterMenu>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
</HeaderContextMenu>
</telerik:RadGrid>
Code behind
==========
Protected Sub rgCriticalCaps_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles rgCriticalCaps.ItemDataBound
If e.Item.ItemType = GridItemType.EditItem And e.Item.IsInEditMode Then
Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
Dim editMan As GridEditManager = editedItem.EditManager
Dim editor As GridDropDownListColumnEditor = TryCast(editMan.GetColumnEditor("Reason"), GridDropDownListColumnEditor)
Dim SqlBuilder As StringBuilder = New StringBuilder
SqlBuilder.Append("SELECT PK_PickList,DisplayValue FROM PickLists WHERE PK_PickListType IN (SELECT PK_PickListType FROM PickListTypes WHERE UsageField = 'Capabilities_Reason_NotMet') order by SortPos")
Dim gridSql As String = SqlBuilder.ToString()
Dim oReason As DataTable = New DataTable
oReason = odbutils.GetDataTable(gridSql)
Dim rComboBox As RadComboBox = editor.ComboBoxControl
rComboBox.DataSource = oReason
rComboBox.DataTextField = "DisplayValue"
rComboBox.DataValueField = "PK_PickList"
rComboBox.DataBind()
Dim drVal = DirectCast(e.Item.DataItem, DataRowView)
If drVal IsNot Nothing Then
editor.SelectedValue = drVal("Reason_not_met").ToString()
Dim dtExpected As RadDatePicker = DirectCast(editedItem("Expected_Date").Controls(0), RadDatePicker)
If drVal("Expected_Date") IsNot Nothing Then
If Not String.IsNullOrEmpty(drVal("Expected_Date").ToString) Then
dtExpected.SelectedDate = drVal("Expected_Date")
End If
End If
End If
End If