This is a migrated thread and some comments may be shown as answers.

a problem about RadGrid in RadGrid

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ky
Top achievements
Rank 1
Ky asked on 07 Dec 2011, 11:26 AM
Hello,
I used RadTelerik to show an grid in grid, here is my code in aspx file:

<telerik:RadGrid runat="server" ID="gridModulesList" BorderStyle="None" BackColor="Transparent"
            BorderColor="Transparent" AutoGenerateColumns="false" ShowHeader="false" Width="100%"
            AutoPostBack="true"  OnItemCommand="gridModulesList_ItemCommand">    
       
            <MasterTableView DataKeyNames="ID">
                <NestedViewTemplate>
                    <asp:Panel runat="server" ID="PnModuleDetail">
                    <telerik:RadGrid ID="gridModuleDetail" runat="server" AutoGenerateColumns="false" ShowHeader="false"  BorderWidth="0" Width="100%"
                            BackColor="White" OnItemDataBound="gridModuleDetail_ItemDataBound" OnItemCommand="gridModuleDetail_ItemCommand"
                            OnSelectedIndexChanged="gridModuleDetail_SelectedIndexChanged" OnNeedDataSource="gridModuleDetail_NeedDataSource"> 

                          <ClientSettings EnablePostBackOnRowClick="True" EnableRowHoverStyle="true" EnableAlternatingItems="true">
                            <Selecting AllowRowSelect="True" />
                        </ClientSettings>
                        <MasterTableView >
                            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            </RowIndicatorColumn>
                            <Columns>
                            <telerik:GridBoundColumn DataField="ID" UniqueName="ID" Visible="false">
                                </telerik:GridBoundColumn>                                
                            <telerik:GridTemplateColumn UniqueName="Name">
                                <ItemTemplate>                                    
                                    <asp:Label runat="server" ID="lblName"></asp:Label>
                                </ItemTemplate>                                
                            </telerik:GridTemplateColumn>                                                                
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
                    </asp:Panel>
                </NestedViewTemplate>
                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                </RowIndicatorColumn>
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" UniqueName="ID" Visible="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Name" UniqueName="Name" Visible="true">
                    </telerik:GridBoundColumn>                    
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>


The problem is:
When I click on a item=> this item is selected and it's bold (item1)
I continue click on the other item item2=> item2 is selected and it's bold and item1 is still bold
Expected:
When I click on item2=> item1 is not selected and it's not BOLD


1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 12 Dec 2011, 02:26 PM
Hello Ky,

To achieve the desired functionality you should handle ItemCommand event of the nested grid, clear the selected indexes and set only current selected item as selected.

Here is the code:
protected void gridModuleDetail_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "RowClick")
        {
            foreach (GridNestedViewItem nestedItem in gridModulesList.MasterTableView.GetItems(GridItemType.NestedView))
            {
                RadGrid innerGrid = nestedItem.FindControl("gridModuleDetail") as RadGrid;
                innerGrid.SelectedIndexes.Clear();
            }
            e.Item.Selected = true;
        }
    }

I am also attaching a sample project which handles the needed functionality.

Greetings,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Ky
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or