HierarchyLoadMode = "Conditional" Row Selection Not Added to RadGrid SelectedItems

0 Answers 44 Views
Ajax AjaxPanel Grid
John
Top achievements
Rank 1
John asked on 25 Mar 2024, 03:57 PM

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.

Attila Antal
Telerik team
commented on 28 Mar 2024, 01:46 PM

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.

John
Top achievements
Rank 1
commented on 28 Mar 2024, 06:56 PM

Hi Attila, 

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>
AJAX-
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableAJAX="true" EnablePageMethods="true">
    <telerik:AjaxSetting AjaxControlID="sampleRadGrid">
        <UpdatedControls>
            <telerik:AjaxUpdatedControl ControlID="sampleRadGrid" LoadingPanelID="sampleLoadingPanel" />
        </UpdatedControls>
    </telerik:AjaxSetting>
NeedDataSource-
        Private Sub sampleRadGrid_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles sampleRadGrid.NeedDataSource
            Dim sampleRadGridDataSet As New DataSet()
            sampleDBCall(sampleRadGridDataSet)
            sampleRadGrid.DataSource = sampleRadGridDataSet
       End Sub
DetailTableDataBind-
        Protected Sub sampleRadGrid_DetailTableDataBind(ByVal sender As Object, ByVal e As GridDetailTableDataBindEventArgs)
            Dim detailTableView As GridTableView = e.DetailTableView
            Dim detailTableDataSet As New DataSet()
            sampleDBCall(detailTableDataSet)
            detailTableView.DataSource = detailTableDataSet
        End Sub
"Process Data" function-
* 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.
Private Sub processData(sender As Object, e As EventArgs) Handles sampleButton.Click
            Dim selected As GridItemCollection = sampleRadGrid.MasterTableView.DetailTables(0).ChildSelectedItems
            processDataFunction(selected)
End Sub
"Process Data" button AJAX-
<telerik:AjaxSetting AjaxControlID="sampleButton">
    <UpdatedControls>
        <telerik:AjaxUpdatedControl ControlID="sampleRadGrid" LoadingPanelID="LoadingPanel1" />
    </UpdatedControls>
</telerik:AjaxSetting>

No answers yet. Maybe you can help?

Tags
Ajax AjaxPanel Grid
Asked by
John
Top achievements
Rank 1
Share this question
or