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

RadGrid DetailTables SelectedValue

1 Answer 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
archimede
Top achievements
Rank 1
archimede asked on 22 Jun 2010, 05:24 PM
I have a RadGrid with a nested DetailTables section, below there's the aspx code.
When the user clicks on a details row I want to get in C# code the DetailsTable selected DataKey or a telerik:GridBoundColumn value. I've tried attaching to RadGridAspnetUsers_ItemCommand event but couldn't find how to get the value.

Someone can help?

<telerik:RadGrid ID="RadGridAspnetUsers" runat="server" DataSourceID="ObjectDataSourceAspnetUser" 
                EnableEmbeddedSkins="False" GridLines="None" Skin="MachinaWeb" OnDetailTableDataBind="RadGridAspnetUsers_DetailTableDataBind" 
                OnItemCommand="RadGridAspnetUsers_ItemCommand" Height="670px"
                <ClientSettings EnablePostBackOnRowClick="True" AllowExpandCollapse="False" AllowGroupExpandCollapse="False"
                    <Selecting AllowRowSelect="True" /> 
                    <Scrolling AllowScroll="True" EnableVirtualScrollPaging="True" /> 
                </ClientSettings> 
                <MasterTableView AutoGenerateColumns="False" DataSourceID="ObjectDataSourceAspnetUser" 
                    DataKeyNames="UserId"
                    <CommandItemTemplate> 
                    </CommandItemTemplate> 
                    <RowIndicatorColumn> 
                        <HeaderStyle Width="20px" /> 
                    </RowIndicatorColumn> 
                    <ExpandCollapseColumn> 
                    </ExpandCollapseColumn> 
                    <Columns> 
                        <telerik:GridBoundColumn DataField="Cognome" HeaderText="Cognome" SortExpression="Cognome" 
                            UniqueName="Cognome" ItemStyle-Width="120px"
                            <ItemStyle Width="200px" /> 
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Nome" HeaderText="Nome" SortExpression="Nome" 
                            UniqueName="Nome" ItemStyle-Width="120px"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="UserId" DataType="System.Guid" HeaderText="UserId" 
                            SortExpression="UserId" UniqueName="UserId" Visible="false"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="UserName" HeaderText="UserName" SortExpression="UserName" 
                            UniqueName="UserName" ItemStyle-Width="100px"
                            <ItemStyle Width="100px" /> 
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Email" HeaderText="Email" SortExpression="Email" 
                            UniqueName="Email" ItemStyle-Width="120px"
                            <ItemStyle Width="200px" /> 
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="UserId" HeaderText="UserId" SortExpression="UserId" 
                            UniqueName="UserId" ItemStyle-Width="150px" Visible="false"
                            <ItemStyle Width="150px" /> 
                        </telerik:GridBoundColumn> 
                    </Columns> 
                    <EditFormSettings> 
                        <EditColumn> 
                        </EditColumn> 
                    </EditFormSettings> 
                    <DetailTables> 
                        <telerik:GridTableView runat="server" DataSourceID="ObjectDataSourceUtenti" EnableEmbeddedSkins="False" 
                            GridLines="None" Skin="MachinaWeb" OnItemCommand="ccc" 
                            AutoGenerateColumns="false" CssClass="RadGridUtentiMachinaDetailTable" Width="700px"
                            <ParentTableRelation> 
                                <telerik:GridRelationFields DetailKeyField="IdUtenteAsp" MasterKeyField="UserId" /> 
                            </ParentTableRelation> 
                            <Columns> 
                                <telerik:GridBoundColumn DataField="IdUtente" DataType="System.Int64" HeaderText="IdUtente" 
                                    SortExpression="IdUtente" UniqueName="IdUtente" Visible="false"
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="IdUtenteAsp" HeaderText="IdUtenteAsp" SortExpression="IdUtenteAsp" 
                                    UniqueName="IdUtenteAsp" DataType="System.Guid" Visible="false"
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="UserName" HeaderText="UserName" SortExpression="UserName" 
                                    UniqueName="UserName" Visible="false"
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="IdCultura" DataType="System.Int64" HeaderText="IdCultura" 
                                    ReadOnly="True" SortExpression="IdCultura" UniqueName="IdCultura" Visible="false"
                                </telerik:GridBoundColumn> 
                                <telerik:GridDropDownColumn DataField="IdAzienda" HeaderText="Azienda" SortExpression="Azienda" 
                                    UniqueName="Azienda" ListTextField="NomeAzienda" ListValueField="IdAzienda" DataSourceID="ObjectDataSourceAzienda" ItemStyle-Width="100px"
                                </telerik:GridDropDownColumn> 
                                <telerik:GridDropDownColumn HeaderText="Cultura" SortExpression="Cultura" DataSourceID="ObjectDataSourceCultura" 
                                    ListTextField="Cultura" ListValueField="IdCultura" DataField="IdCultura" UniqueName="Cultura" 
                                    ItemStyle-Width="40px"
                                    <ItemStyle Width="40px" /> 
                                </telerik:GridDropDownColumn> 
                                <telerik:GridBoundColumn DataField="IdGruppo" HeaderText="IdGruppo" SortExpression="IdGruppo" 
                                    UniqueName="IdGruppo" Visible="false" ReadOnly="True"
                                </telerik:GridBoundColumn> 
                                <telerik:GridDropDownColumn HeaderText="Gruppo" SortExpression="Gruppo" UniqueName="Gruppo" 
                                    DataField="IdGruppo" ListTextField="Nome" ListValueField="IdGruppoUtente" DataSourceID="ObjectDataSourceGruppoUtente" 
                                    ItemStyle-Width="80px"
                                    <ItemStyle Width="80px" /> 
                                </telerik:GridDropDownColumn> 
                                <telerik:GridDropDownColumn HeaderText="Stabilimento" SortExpression="Stabilimento" 
                                    UniqueName="Stabilimento" ListTextField="Denominazione" ListValueField="IdStabilimento" 
                                    DataField="IdStabilimento" DataSourceID="ObjectDataSourceStabilimento" ItemStyle-Width="100px"
                                    <ItemStyle Width="100px" /> 
                                </telerik:GridDropDownColumn> 
                                <telerik:GridDropDownColumn HeaderText="Reparto" SortExpression="Reparto" UniqueName="Reparto" 
                                    DataSourceID="ObjectDataSourceReparto" ListTextField="Reparto" ListValueField="IdReparto" 
                                    DataField="IdReparto" ItemStyle-Width="100px"
                                    <ItemStyle Width="100px" /> 
                                </telerik:GridDropDownColumn> 
                                <telerik:GridBoundColumn HeaderText="IdAziendaCorrente" SortExpression="IdAziendaCorrente" 
                                    UniqueName="IdAziendaCorrente" DataField="IdAziendaCorrente" Visible="false"
                                </telerik:GridBoundColumn> 
                            </Columns> 
                            <EditFormSettings> 
                                <EditColumn> 
                                </EditColumn> 
                            </EditFormSettings> 
                        </telerik:GridTableView> 
                    </DetailTables> 
                </MasterTableView> 
                <FilterMenu EnableEmbeddedSkins="False"
                </FilterMenu> 
                <HeaderContextMenu EnableEmbeddedSkins="False"
                </HeaderContextMenu> 
            </telerik:RadGrid> 




1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Jun 2010, 07:46 AM
Hello Archimede,

You can try the following code snippet in ItemCommand event to access the DataKeyValue of selected rows in DetailTable.

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "RowClick"
        { 
           GridDataItem item = (GridDataItem)e.Item; 
           if (e.Item.OwnerTableView.Name == "Master")   //check with name of MasterTableView 
            { 
               string id = item.GetDataKeyValue("UserId").ToString();  //access DataKeyValue of MasterTableView 
            } 
            if (e.Item.OwnerTableView.Name == "DetailTableView1")   //check with name of DetailTableView 
            { 
                foreach (GridDataItem childitem in item.OwnerTableView.ChildSelectedItems) 
                { 
                    string id = childitem.GetDataKeyValue("IdUtenteAsp").ToString();  //access DataKeyValue of DetailTableView 
                } 
            } 
        } 
    } 

Thanks,
Princy.

Tags
Grid
Asked by
archimede
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or