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

[Solved] Get Selected Items in Hierarchy

6 Answers 406 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mro
Top achievements
Rank 1
mro asked on 19 Jun 2008, 07:17 PM
Hello,
Does anybody know how to get selected items in a hierarchy? I am using telerik ajax grid Q1 and there are 3 levels. Hierarchy load mode is client. I tried something like this but it is not working.When I select a row in a 3 rd level I got nothing.

 
 foreach (Telerik.Web.UI.GridDataItem gridDataItem in grdEligible.Items) 
        { 
            if (gridDataItem.ItemType == Telerik.Web.UI.GridItemType.Item || 
              gridDataItem.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem) 
            { 
                if (gridDataItem.Selected) 
                { 
                    string id = (string)gridDataItem.OwnerTableView.DataKeyValues[gridDataItem.ItemIndex]["cust_num"]; 
                    ids.Add(id); 
                } 
 
               if (gridDataItem.HasChildItems) 
                { 
                     
                    foreach (Telerik.Web.UI.GridNestedViewItem childItem in gridDataItem.OwnerTableView.GetItems(Telerik.Web.UI.GridItemType.NestedView)) 
                    { 
                        if (childItem.Selected) 
                        { 
                            string id = (string)childItem.OwnerTableView.DataKeyValues[childItem.ItemIndex]["cust_num"]; 
                            ids.Add(id); 
                        } 
 
                    } 
                } 
            } 
        } 

Thank you,
Mario

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Jun 2008, 05:07 AM
Hi Mario ,

Set the Name property fo rthe Detail table and try to access the selected item as shown below.

CS:
protected void Button1_Click(object sender, EventArgs e)  
    {  
        foreach (GridDataItem item in RadGrid1.Items)  
        {  
            if ((item.OwnerTableView.Name=="Detail")&&(item.Selected))  
            {  
                string strtxt = item["ProductName"].Text.ToString();  
            }  
        }  
    } 


Thanks
Princy.
0
mro
Top achievements
Rank 1
answered on 20 Jun 2008, 09:16 AM

Princy,
This is not working:

if ((item.OwnerTableView.Name=="Detail")&&(item.Selected))    
 

"item.Selected" is always FALSE.

There are 3 nested tables and I need to get selected rows. Do you know any other way?

Thank you,

Mario

 

0
Shinu
Top achievements
Rank 2
answered on 20 Jun 2008, 10:08 AM
Hi Mario ,

Have you set the Name Property for the Detail Table? Try setting it in the aspx as shown below.

ASPX:
<DetailTables > 
 <telerik:GridTableView runat="server" Name="Detail"  DataSourceID="SqlDataSource1" > 


Shinu.
0
mro
Top achievements
Rank 1
answered on 20 Jun 2008, 12:18 PM
Hi Shinu,
Yes, I did setup the table names for all 3 tables. When I select a row in the first or second table it is working but when there is a selected row in a 3rd table nothing happens. If I select a row in all 3 tables again I don't get anything, not even a selected row from the master table.
Here is how the grid looks like:

 <telerik:RadGrid ID="grdEligible" runat="server"   
                                                                    AllowPaging="True"   
                                                                    AllowSorting="True" 
                                                                    AllowMultiRowSelection="True"   
                                                                    AutoGenerateColumns="False"   
                                                                    GridLines="None"   
                                                                    PageSize="20" 
                                                                    Width="100%"   
                                                                    Skin="Telerik"   
                                                                    
                                                                    OnNeedDataSource="grdEligible_NeedDataSource" 
                                                                    OnDataBound="grdEligible_DataBound"   
                                                                    OnDetailTableDataBind="grdEligible_DetailTableDataBind"   
                                                                    OnPreRender="grdEligible_PreRender">  
                                                                    <MasterTableView DataKeyNames="cust_num,parent_cust_num" 
                                                                    HierarchyLoadMode="client" 
                                                                    Width="100%" 
                                                                    PageSize="10"   
                                                                    Name="EligDealers0" 
                                                                    > 
                                                                        <Columns> 
                                                                            <telerik:GridBoundColumn DataField="cust_num" HeaderText="Dealer Id" ReadOnly="True" 
                                                                                SortExpression="cust_num" UniqueName="cust_num">  
                                                                                  
                                                                            </telerik:GridBoundColumn> 
                                                                            <telerik:GridBoundColumn DataField="cust_1_name" HeaderText="Dealership Name" SortExpression="cust_1_name" 
                                                                                UniqueName="cust_1_name">  
                                                                                  
                                                                            </telerik:GridBoundColumn>                                                                                                                                    
                                                                            <telerik:GridClientSelectColumn Reorderable="False" UniqueName="ClientSelectColumn">  
                                                                                 
                                                                            </telerik:GridClientSelectColumn> 
                                                                        </Columns> 
                                                                        <ExpandCollapseColumn Resizable="False" Visible="False">  
                                                                            <HeaderStyle Width="20px" /> 
                                                                        </ExpandCollapseColumn> 
                                                                        <RowIndicatorColumn Visible="False">  
                                                                            <HeaderStyle Width="20px" /> 
                                                                        </RowIndicatorColumn> 
                                                                            <DetailTables> 
                                                                                <telerik:GridTableView Name="EligDealers1" Width="100%" AllowPaging="true" PageSize="10" ShowHeadersWhenNoRecords="False" 
                                                                                    runat="server" DataKeyNames="cust_num,parent_cust_num" HierarchyLoadMode="Client">  
                                                                                    <ParentTableRelation> 
                                                                                        <telerik:GridRelationFields DetailKeyField="parent_cust_num" MasterKeyField="cust_num" /> 
                                                                                    </ParentTableRelation> 
                                                                                    <RowIndicatorColumn Visible="False">  
                                                                                        <HeaderStyle Width="20px" /> 
                                                                                    </RowIndicatorColumn> 
                                                                                    <ExpandCollapseColumn Resizable="False" Visible="False">  
                                                                                        <HeaderStyle Width="20px" /> 
                                                                                    </ExpandCollapseColumn> 
                                                                                    <EditFormSettings> 
                                                                                        <PopUpSettings ScrollBars="None" /> 
                                                                                    </EditFormSettings> 
                                                                                    <Columns> 
                                                                                        <telerik:GridBoundColumn DataField="cust_num" HeaderText="Dealer Id" ReadOnly="True" 
                                                                                            SortExpression="cust_num" UniqueName="cust_num">  
                                                                                        </telerik:GridBoundColumn> 
                                                                                        <telerik:GridBoundColumn DataField="cust_1_name" HeaderText="Dealership Name" SortExpression="cust_1_name" 
                                                                                            UniqueName="cust_1_name">  
                                                                                        </telerik:GridBoundColumn>                                                                                         
                                                                                        <telerik:GridBoundColumn DataField="parent_cust_num" HeaderText="Parent Id" 
                                                                                            SortExpression="parent_cust_num" UniqueName="parent_cust_num">  
                                                                                        </telerik:GridBoundColumn> 
                                                                                        <telerik:GridClientSelectColumn Reorderable="False" UniqueName="ClientSelectColumn">  
                                                                                            <HeaderStyle Width="20px"></HeaderStyle> 
                                                                                        </telerik:GridClientSelectColumn> 
                                                                                    </Columns> 
                                                                                      
                                                                                    <DetailTables> 
                                                                                    <telerik:GridTableView Name="EligDealers2"   Width="100%"  AllowPaging="true" PageSize="10" ShowHeadersWhenNoRecords="False" 
                                                                                    runat="server"  DataKeyNames="cust_num,parent_cust_num" HierarchyLoadMode="client">  
                                                                                    <ParentTableRelation> 
                                                                                        <telerik:GridRelationFields DetailKeyField="parent_cust_num" MasterKeyField="cust_num" /> 
                                                                                    </ParentTableRelation> 
                                                                                    <RowIndicatorColumn Visible="False">  
                                                                                        <HeaderStyle Width="20px" /> 
                                                                                    </RowIndicatorColumn> 
                                                                                    <ExpandCollapseColumn Resizable="False" Visible="False">  
                                                                                        <HeaderStyle Width="20px" /> 
                                                                                    </ExpandCollapseColumn> 
                                                                                    <EditFormSettings> 
                                                                                        <PopUpSettings ScrollBars="None" /> 
                                                                                    </EditFormSettings> 
                                                                                    <Columns> 
                                                                                        <telerik:GridBoundColumn DataField="cust_num" HeaderText="Dealer Id" ReadOnly="True" 
                                                                                            SortExpression="cust_num" UniqueName="cust_num">  
                                                                                            <HeaderStyle Width="70px" /> 
                                                                                        </telerik:GridBoundColumn> 
                                                                                        <telerik:GridBoundColumn DataField="cust_1_name" HeaderText="Dealership Name" SortExpression="cust_1_name" 
                                                                                            UniqueName="cust_1_name">  
                                                                                            <HeaderStyle Width="200px" /> 
                                                                                        </telerik:GridBoundColumn> 
                                                                    
                                                                                        <telerik:GridBoundColumn DataField="parent_cust_num" HeaderText="Parent Id" 
                                                                                            SortExpression="parent_cust_num" UniqueName="parent_cust_num">  
                                                                                        </telerik:GridBoundColumn> 
                                                                                        <telerik:GridClientSelectColumn Reorderable="False" UniqueName="ClientSelectColumn">  
                                                                                            <HeaderStyle Width="20px"></HeaderStyle> 
                                                                                        </telerik:GridClientSelectColumn> 
                                                                                    </Columns>                                            
                                                                                </telerik:GridTableView> 
                                                                                    </DetailTables> 
                                                                                </telerik:GridTableView>                                                                                  
                                                                            </DetailTables> 
                                                                    </MasterTableView> 
                                                                    <ClientSettings AllowExpandCollapse="true" > 
                                                                    <Selecting  AllowRowSelect="True"  EnableDragToSelectRows="False"></Selecting>               
                                                                    </ClientSettings> 
                                                                </telerik:RadGrid> 
 

The detail tables are bound in a  DetailTableDataBind. The stored proc used is very complex and I cannot paste it here but it is returning a hierarchy of dealerships to which all 3 tables are bound. Tried changing hierarchy load mode to serverbind and no luck.
0
mro
Top achievements
Rank 1
answered on 23 Jun 2008, 08:37 AM
Should I write a support ticket?
0
Iana Tsolova
Telerik team
answered on 23 Jun 2008, 10:24 AM
Hi mro,

Attached sample project with the desired functionality. Try it on you end and let me know if missed something from your logic.

Regards,
Iana
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
mro
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
mro
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Iana Tsolova
Telerik team
Share this question
or