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

Grid with Detail Tables question

3 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom Edward
Top achievements
Rank 1
Tom Edward asked on 22 Mar 2012, 08:56 PM
Hello, I have a Radgrid with a DetailTable inside. This Grid has orders with order items in the detail table.
I have a OnDataBound event on this Grid. This event checks for the value in a column and then sets the row backcolor on it.
It works fine until I try to expand into the detailtable since then it tries to execute the OnDatabound event and the field I am checking does not exists in the detail table.
Below is the OnDataBound event:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = (GridDataItem)e.Item;
                TableCell myCell = dataItem["ready"];
                if ((myCell.Text == "True"))
                {
                    dataItem.BackColor = System.Drawing.Color.SteelBlue;
                }
            }
        }

The code fails when trying to expand into the detail table. It fails on line:
TableCell myCell = dataItem["ready"]; 
since the "ready" column does not exist in the detail table.

 Can someone let me know how I can fix this?
Thanks.

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 23 Mar 2012, 06:05 AM
Hi Tom,

Inorder to differentiate the rows in Master table and detail table , you can give different Name property to each TableView like below.

aspx:
<MasterTableView  Name="Master" >

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Master")
    {
        GridDataItem dataItem = (GridDataItem)e.Item;
        TableCell myCell = dataItem["ready"];
        if ((myCell.Text == "True"))
        {
            dataItem.BackColor = System.Drawing.Color.SteelBlue;
        }
    }
}

Regards,
-Shinu.
0
Tom Edward
Top achievements
Rank 1
answered on 23 Mar 2012, 02:32 PM
Thanks Shinu, that worked!
0
Shinu
Top achievements
Rank 2
answered on 24 Mar 2012, 09:30 AM
Hi Tom,

Happy to know that I was able to help you.

Regards,
-Shinu.

Tags
Grid
Asked by
Tom Edward
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Tom Edward
Top achievements
Rank 1
Share this question
or