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

ItemDataBound conditional format Detail Table Row

2 Answers 253 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 12 Jul 2013, 03:29 PM
What is the best way to determine if the ItemDataBound is Master or Detail Table?

I am trying to conditionally format the detail table row, not cell.  This is based on a column that exists in both the Master and Detail tables.  The formatting is working, but it is formatting both the Master and the detail table.


I see this code, but cannot figure out how to determine if e.Item is Master or Detail table:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = e.Item as GridDataItem;
        if (dataItem["Country"].Text == "Mexico")
            dataItem.CssClass = "MyMexicoRowClass";
    }
}


Or if there is a better way to do this?

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 13 Jul 2013, 08:57 AM
Hello,

<MasterTableView Name="parent">
           <DetailTables>
               <telerik:GridTableView Name="child1">
                   <DetailTables>
                       <telerik:GridTableView Name="child2">
                       </telerik:GridTableView>
                   </DetailTables>
               </telerik:GridTableView>
           </DetailTables>
       </MasterTableView>
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            if (e.Item.OwnerTableView.Name == "parent")
            {
                 // from parent
            }
            else if (e.Item.OwnerTableView.Name == "child1")
            {
                 // from first child
            }
            else if (e.Item.OwnerTableView.Name == "child2")
            {
                // from second child
            }
 
        }
}


Thanks,
Jayesh Goyani
0
Michael
Top achievements
Rank 1
answered on 13 Jul 2013, 12:08 PM
Much appreciated.  Worked like a champ once I figured out what the table name was from the Dataset.

Thanks again!
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Share this question
or