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

Traversing and obtaining values in ItemDataBind for MasterTable

2 Answers 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Karl Wilkens
Top achievements
Rank 1
Karl Wilkens asked on 05 May 2010, 08:53 PM
Hi,

We have a three tiered hierarchy and we are utilizing the OwerTableView.Name property to determine which section we are working on within ItemDataBound (where we are changing colors, adding links, etc, depending on values).

In our top level table (dataset with 3 tables is returned via sql), we have a status flag - Cancel, Refund, etc.

In the DetailTables we need to turn on/off different options such as Editing, when the status of the top most table is 'Cancel'

So my question is this - is there a way to reference values in the MasterTableView, in ItemDataBound, when the current tableView is one of the detailtables?

Put another way, is it possible to traverse up the grid's data structure within ItemDataBound? Hopefully my question makes sense. Thanks.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 May 2010, 06:09 AM
Hello Karl,

You can access the values in Parent tables by using following code snippet.

C#:

 
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
      if (e.Item is GridDataItem) 
        { 
           if (e.Item.OwnerTableView.Name == "DetailTableView1"
            { 
              GridDataItem item = (GridDataItem)e.Item; 
              GridDataItem item1 = (GridDataItem)item.OwnerTableView.ParentItem;//Access the immediate parent's tables value  
              string status = item1["Status"].Text; 
              if (status == "Cancel"
               { 
                  //your code                    
               } 
            } 
           if (e.Item.OwnerTableView.Name == "DetailTableView2"
           { 
              GridDataItem item = (GridDataItem)e.Item; 
              GridDataItem item1 = (GridDataItem)item.OwnerTableView.ParentItem.OwnerTableView.ParentItem;//Access the mastertable column value  
              string status = item1["Status"].Text; 
              if (status == "Cancel"
              { 
                  //your code                    
              } 
           } 
        } 
  } 

Regards,
Shinu.





0
Karl Wilkens
Top achievements
Rank 1
answered on 06 May 2010, 03:42 PM
Thank You Shinu! Works perfectly.
Tags
Grid
Asked by
Karl Wilkens
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Karl Wilkens
Top achievements
Rank 1
Share this question
or