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

how fetch column value from DetailTables

4 Answers 230 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mohsinjk jk
Top achievements
Rank 1
mohsinjk jk asked on 26 Jul 2010, 08:12 AM
Hi

I am working on RadGrid. In this grid I have MasterTableView and one DetailTables. Basically i want to fetch values from DetailTables specific column on the bases of select row of MasterTableView. 

Regards
Mohsin JK

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Jul 2010, 10:46 AM
Hello Mohsin,

Check out the following code snippet which access the values of DetailTable based on selected row of MasterTable.

ASPX:
<telerik:GridButtonColumn Text="Select" CommandName="Select">
</telerik:GridButtonColumn>

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
 {
     if (e.CommandName == "Select")
     {
         GridDataItem item = (GridDataItem)e.Item;
         foreach (GridDataItem childItem in item.ChildItem.NestedTableViews[0].Items)
         {
             string value= childItem["ColumnUniqueName"].Text;
         }
     }
 }

Thanks,
Princy.
0
mohsinjk jk
Top achievements
Rank 1
answered on 26 Jul 2010, 02:55 PM
Basically i want my Rad Grid have 2 level. 
1st level contain my Order&
2nd level contain Order Detail.

Inside 2nd level grid i put a checkbox template field. and I want to pick only those rows which are checked in checkbox column.

        
         foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
            {
                if ((dataItem.FindControl("chkSubRows") as CheckBox).Checked == true)
                {
                    InvoiceIDarray.Add(Convert.ToInt32(dataItem.Cells[2].Text));
                }
                if ((dataItem.FindControl("chkSubRows") as CheckBox).Checked == false)
                {
                    InvoiceIDarray.Remove(Convert.ToInt32(dataItem.Cells[2].Text));
                }
            }

Using this code i can check but only for 1st level grid.

I need help how i can get specific values from hierarchy grid. 

0
Princy
Top achievements
Rank 2
answered on 27 Jul 2010, 08:32 AM
Hello Mohsin,

Check out the sample code below which loops through all MasterTable and DetailTable items to get the value of specific cell in DetailTable in which the CheckBox is checked. You can make your own changes accordingly.

C#:
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)//loops through each MasterTable item
       {
           GridTableView tableView = (GridTableView)item.ChildItem.NestedTableViews[0];
           foreach (GridDataItem childItem in tableView.Items)//loops through each DetailTable item
           {
               CheckBox chk = (CheckBox)childItem.FindControl("CheckBox2");// Id of CheckBox in DetailTable
               if (chk.Checked)
               {
                   string value = childItem["ColumnUniqueName"].Text;// accessing cell value in DetailTable
               }
           }
       }

Hope this helps,
Princy.
0
mohsinjk jk
Top achievements
Rank 1
answered on 02 Aug 2010, 09:17 AM
Thanks dear
Tags
Grid
Asked by
mohsinjk jk
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
mohsinjk jk
Top achievements
Rank 1
Share this question
or