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

get specific column for every row in details tables

3 Answers 302 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Howard
Top achievements
Rank 1
Howard asked on 06 Nov 2012, 07:01 AM
Hi everyone.I have a "level2" details tables within a MasterRadGrid.MasterTableView. In my level2  details tables have 5 rows record with column "ID" and "Name",Now I want to use the "for each" loop to get "ID" column only for each row. How do I achieve this. Please help

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Nov 2012, 07:34 AM
Hi,

Please try the following code snippets to loop through the DetailTable items.

1. Please specify the Name property of the GridTableView in ASPX.

ASPX:
<telerik:GridTableView  Name="Second" . . .>

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
    {
        if (e.Item.OwnerTableView.Name == "Second")
        {
              GridDataItem dataItem = e.Item as GridDataItem;
              string ID = dataItem["ID"].Text;
        }
    }
}

OR

2) Loop through the items of detail grid on an External button click as follows.

C#:
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{
    //loops through each materTable rows
    GridTableView childtableView = (GridTableView)item.ChildItem.NestedTableViews[0];
    foreach (GridDataItem childItem in childtableView.Items)
    {
        string ID1 = childItem["ID"].Text;
    }
}

Hope this helps.

Thanks,
Shinu.
0
Howard
Top achievements
Rank 1
answered on 06 Nov 2012, 09:59 AM
Thanks for your reply,another question is is I wanna use the ID to execute a query from your code below.How should I do?

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
    {
        if (e.Item.OwnerTableView.Name == "Second")
        {
              GridDataItem dataItem = e.Item as GridDataItem;
              string ID = dataItem["ID"].Text;
        }
    }
}

something like this.

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
    {
        if (e.Item.OwnerTableView.Name == "Second")
        {
              GridDataItem dataItem = e.Item as GridDataItem;
              string ID = dataItem["ID"].Text;
 
         --> //SELECT * FROM TABLE WHERE userid=ID
        }
    }
}

please help again.thanks
0
Accepted
Shinu
Top achievements
Rank 2
answered on 07 Nov 2012, 02:57 AM
Hi,

You can pass the 'ID' to the SELECT query as follows.

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
    {
        if (e.Item.OwnerTableView.Name == "Second")
        {
              GridDataItem dataItem = e.Item as GridDataItem;
              string ID = dataItem["ID"].Text;
  
              string selectQuery="SELECT * FROM TABLE WHERE UserID='" + ID + "'";
              //Execute the query
        }
    }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Howard
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Howard
Top achievements
Rank 1
Share this question
or