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

How to check if GridDataItem is from "parent" table

2 Answers 341 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Johan
Top achievements
Rank 1
Johan asked on 07 Feb 2012, 08:04 AM
Hi,

I have a two level hierarchical grid where I need to apply some logic at ItemDataBound etc.

On my ItemDataBound event I check whether a column contains a specific value and based on that I change the font color:

protected void grdCurrentGarnishee_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                var item = e.Item as GridDataItem;
 
                if (item["ValidationState"].Text == "UNMATCHED")
                {
                    item.ForeColor = System.Drawing.Color.Red;
                }
            }
        }

This is working great but is causing some issue when I expand the child (details) table since the child table does not contain that column.

Is there a way to check whether e.Item is from the "parent" table and not details table?

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 07 Feb 2012, 08:23 AM
Hello,

 One suggestion is you can  set the Name for the MasterTableView and DetailTableView and check for the condition as shown below.
C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "MasterTable")
  {
    //checking for the column in MasterTableView
  }
 if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "DetailTable")
  {
    //checking for the column in DetailTableView
  }
}

-Shinu.
0
Johan
Top achievements
Rank 1
answered on 07 Feb 2012, 08:34 AM
Thank you Shinu, exactly what I was looking for!
Tags
Grid
Asked by
Johan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Johan
Top achievements
Rank 1
Share this question
or