New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Multi-row edit/selection only for master table in hierarchical grid

If you enable multi-row selection and editing by setting the RadGrid AllowMultiRowSelection and AllowMultiRowEdit properties to True, in a hierarchical grid, all the tables in the hierarchy allow multi-row selection and editing. If you want to disable these features for the nested tables, you need to do the following:

To disable multi-row editing on detail tables:

  1. Handle the ItemCommand event of the grid.

  2. When e.CommandName is RadGrid.EditCommandName, identify whether you are on the master table view.

  3. If you are not on the master table view, traverse the items in the detail table and set their Edit property to False.

To disable multi-row selection on detail tables:

  1. Handle the RowSelecting client event of the grid.

  2. Verify that the clicked table is a child table by referencing a column from the table.

  3. If the SelectedRows collection length is equal to 1, iterate through the rows in the table and deselect them if they were previously selected.

The following code illustrates this technique on a two-level hierarchy.

This technique can be extended for higher level hierarchies as well.

<script type="text/javascript">
function RowSelecting(sender, eventArgs) {
    var tableView = eventArgs.get_tableView();
    if (eventArgs.get_tableView().get_name() != "Customers") {
      if (tableView.get_selectedItems().length == 1) {
        for (var i = 0; i < tableView.get_dataItems().length; i++) {
          if (tableView.get_dataItems()[i].get_selected()) {
            tableView.selectItem(tableView.get_dataItems()[i].get_element(), false);
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" AllowMultiRowEdit="true" AllowSorting="true"
  DataSourceID="SqlDataSource1" AllowPaging="true" PageSize="3" AllowMultiRowSelection="true"
  <MasterTableView DataKeyNames="CustomerID" Name="Customers">
      <telerik:GridEditCommandColumn />
      <telerik:GridTableView DataKeyNames="OrderID,CustomerID" DataSourceID="SqlDataSource2"
          <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" />
          <telerik:GridEditCommandColumn />
    <Selecting AllowRowSelect="true" EnableDragToSelectRows="true" />
    <ClientEvents OnRowSelecting="RowSelecting" />
<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
  ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Customers"
<asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
  ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Orders Where CustomerID = @CustomerID"
    <asp:Parameter Name="CustomerID" SessionField="CustomerID" Type="string" />
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    if (e.CommandName == RadGrid.EditCommandName && e.Item.OwnerTableView.Name != "Customers")
        foreach (GridItem item in e.Item.OwnerTableView.Items)
            item.Edit = false;
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
    If e.CommandName = RadGrid.EditCommandName AndAlso Not e.Item.OwnerTableView.Name = "Customers" Then
        Dim item As GridItem
        For Each item In e.Item.OwnerTableView.Items
            item.Edit = False
    End If
End Sub
In this article
Not finding the help you need? Improve this article