If you enable multi-row edit/selection for Telerik RadGrid (through the AllowMultiRowEdit/AllowMultiRowSelection properties) these settings will be inherited for the child tables in the grid hierarchy. In case you want to disable these features for the inner tables, you will need to do that with several lines of custom client/server code.
To disable the multi-row edit for detail tables:
- Wire the ItemCommand event of the grid
- Check whether e.CommandName is RadGrid.EditCommandName and Not e.Item.OwnerTableView Is e.Item.OwnerTableView.OwnerGrid.MasterTableView
- Traverse the items in the e.Item.OwnerTableView.Items collection and set their Edit property to false
To disable the multi-row selection for detail tables:
- Hook the RowSelecting client event of the grid
- Verify that the clicked table is child table (referencing a column from that detail table)
- See whether the SelectedRows collection length is equal to 1
- Iterate through the rows in the inner table and deselect them if selected previously
The code below illustrates a sample case (note that it is designed to work with two level hierarchy but can be extended for n-level hierarchy as well):
| ASPX/ASCX |
Copy Code |
|
<script type="text/javascript"> function RowSelecting(rowObject) { if(this.Columns[1].UniqueName == "OrderID") { if(this.SelectedRows.length == 1) { for (var i = 0; i < this.Rows.length; i++) { if(this.Rows[i].Selected) { this.SelectRow(this.Rows[i].Control, false); } } } } } </script> <rad:RadGrid ID="RadGrid1" AllowMultiRowEdit="true" AllowSorting="true" DataSourceID="SqlDataSource1" runat="server" AllowPaging="true" PageSize="3" AllowMultiRowSelection="true"> <MasterTableView DataKeyNames="CustomerID"> <Columns> <rad:GridEditCommandColumn /> </Columns> <DetailTables> <rad:GridTableView DataKeyNames="OrderID,CustomerID" DataSourceID="SqlDataSource2"> <ParentTableRelation> <rad:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" /> </ParentTableRelation> <Columns> <rad:GridEditCommandColumn /> </Columns> </rad:GridTableView> </DetailTables> </MasterTableView> <ClientSettings> <Selecting AllowRowSelect="true" EnableDragToSelectRows="true" /> <ClientEvents OnRowSelecting="RowSelecting" /> </ClientSettings> </rad:RadGrid> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<$ ConnectionStrings>" SelectCommand="SELECT * FROM [Customers]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<$ ConnectionStrings>" SelectCommand="SELECT * FROM [Orders] WHERE ([CustomerID] = @CustomerID)"> <SelectParameters> <asp:SessionParameter Name="CustomerID" SessionField="CustomerID" Type="String" /> </SelectParameters> </asp:SqlDataSource> |
| C# |
Copy Code |
|
protected void RadGrid1_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e) { if (e.CommandName == RadGrid.EditCommandName && e.Item.OwnerTableView != e.Item.OwnerTableView.OwnerGrid.MasterTableView) { GridItem item;
foreach (item in e.Item.OwnerTableView.Items) { item.Edit = false; } } } |
| VB.NET |
Copy Code |
|
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles RadGrid1.ItemCommand If e.CommandName = RadGrid.EditCommandName AndAlso Not e.Item.OwnerTableView Is e.Item.OwnerTableView.OwnerGrid.MasterTableView Then Dim item As GridItem For Each item In e.Item.OwnerTableView.Items item.Edit = False Next End If End Sub |