I have a Telerik RadGrid that has a DetailTable that can be expanded by the user. The DetailTable contains several selectable rows. The user is able to select some rows, then click a "Process Data" button that saves the row data in a Visual Basic code-behind file.
The RadGrid uses HierarchyLoadMode="conditional" to keep track of the DetailTable.
Two Problems-
1. When a user:
- expands the DetailTable,
- selects a row,
- collapses the DetailTable,
- clicks "Process Data,"
no data is saved because RadGrid.SelectedItems has 0 items. Even though the selected row is shown as selected in the UI.
However, if a user:
- selects a row,
- collapses the detail table,
- clicks "Process Data" + gets an error from the VB saying "No rows selected,"
- expands the detail table again,
- selects the row again,
- clicks "Process Data" again,
then the data will be saved because RadGrid.SelectedItems will include the row. Perhaps this is a bug?
In other words, a post back is needed to clear the detail table selections before RadGrid.SelectedItems actually includes items that have been selected in a collapsed HierarchyLoadMode="conditional" table.
2. Is there a way to have selections persist across pagination? Eg. If the user expands the DetailTable, selects a row, navigates to "page 2" of the detail table, then navigates back to "page 1," their selection is not saved.
Hi John,
Without seeing the current implementation (Markup + VB code) of the Grid component, I can't tell what is good and what is bad. However, I can tell from experience, that most issues with the Grid happen because of incorrect data binding.
Make sure the Grid is bound either through the Declarative DataSource Controls or programmatically using the NeedDataSource event. Once this is done, also ensure that the DataBind() method is not called anywhere for the Grid. This method should never be used. To force-refresh the Grid, use the Rebind() method.
To be able to tell you more, I would need to see the complete implementation.
Please share all the code used to configure and bind the Grid and I will take a look at it.
Thank you for your response. I'll go through my code and make sure DataBind() is not being called anywhere. I'll also check up on the databinding.
In the meantime, pasted below is the relevant code-
Markup-
<telerik:RadGrid ID="sampleRadGrid" runat="server" AllowPaging="True" AllowCustomPaging="True" SkinID="Default" PageSize="20" AllowAutomaticDeletes="false" AllowAutomaticUpdates="false" AllowMultiRowSelection="true" OnDetailTableDataBind="sampleRadGrid_DetailTableDataBind" RetainExpandStateOnRebind="True" HierarchyLoadMode="Conditional" EnableViewState="true"> <ClientSettings> <Selecting AllowRowSelect="true" /> <ClientEvents OnRowSelected="rowSelectedFunction" OnRowDeselected="rowDeselectedSelectedFunction"/> </ClientSettings> <MasterTableView Name="SampleTable" runat="server" Width="100%" HierarchyLoadMode="Conditional" ShowHeader="True" ShowFooter="True" AllowPaging="True" AllowCustomPaging="True" PageSize="20" AllowFilteringByColumn="True" DataMember="SampleDataTable" EnableHierarchyExpandAll="True" EnableGroupsExpandAll="True" RetainExpandStateOnRebind="True" DataKeyNames="SampleData1, SampleData2"> <Columns> <telerik:GridClientSelectColumn UniqueName="sampleRadGrid_ClientSelectColumn" Display="True" HeaderStyle-Width="35px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" /> <telerik:GridBoundColumn HeaderText="Header 1" DataField="SampleData1" UniqueName="SampleData1" SortExpression="SampleData1" HeaderStyle-Width="50%" FilterControlWidth="70%" /> <telerik:GridBoundColumn HeaderText="Header 2" DataField="SampleData2" UniqueName="SampleData2" SortExpression="SampleData2" HeaderStyle-Width="100%" FilterControlWidth="70%" /> <ItemTemplate> <strong> <asp:Label ID="sampleLabel" runat="server" Text='sampleText'/> </strong> </ItemTemplate> </telerik:GridTemplateColumn> <DetailTables> <telerik:GridTableView Name="SampleDetailTable" runat="server" Width="100%" HierarchyLoadMode="Conditional" ShowHeader="True" AllowPaging="True" AllowCustomPaging="True" PageSize="20" AllowFilteringByColumn="True" EnableHierarchyExpandAll="True" EnableGroupsExpandAll="True" RetainExpandStateOnRebind="True" DataKeyNames="SampleDetailData1, SampleDetailData2"> <Columns> <telerik:GridClientSelectColumn UniqueName="SampleDetailData1" Display="True" HeaderStyle-Width="35px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" /> <telerik:GridBoundColumn HeaderText="Sample Header" DataField="SampleDetailData2" UniqueName="SampleDetailData2" SortExpression="SampleDetailData2" HeaderStyle-Width="100%" /> </Columns> </telerik:GridTableView> </DetailTables> </MasterTableView> </telerik:RadGrid>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableAJAX="true" EnablePageMethods="true"> <telerik:AjaxSetting AjaxControlID="sampleRadGrid"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="sampleRadGrid" LoadingPanelID="sampleLoadingPanel" /> </UpdatedControls> </telerik:AjaxSetting>
* For some reason, ChildSelectedItems is empty here if a row in the DetailTable has been selected, then the table collapsed. After the Rebind is called & the row is reselected, it is included in ChildSelectedItems.
<telerik:AjaxSetting AjaxControlID="sampleButton"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="sampleRadGrid" LoadingPanelID="LoadingPanel1" /> </UpdatedControls> </telerik:AjaxSetting>