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

.PageRequestManagerServerErrorException: Object reference not set to an instance of an object - RadGrid Child Grid show

1 Answer 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 19 Mar 2012, 10:00 AM
Hi

I have a RadGrid Control which displays a child grid when the Parent Grid Row is clicked.
This works without issues.

In order to make it clearer to the user, I wish to change the background colour of one of the Cells in the row.  This is dependant upon the value contained within another column.  (Basically some rows will have more than 1 detail row - so I want to indicate this to the user)

When I add this functionality to the ItemDataBound event of the grid, it throws a "PageRequestManagerServerErrorException Object reference not set to an instance of an object." error. when I try to expand the child row.  The colour change is is showing correctly.

if (e.Item is GridDataItem)
 {
        if (e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["DocTypes"].ToString() == "Multiple")
        {
            // Find Column and change colours
            GridDataItem item = (GridDataItem)e.Item;
            item["DocReferences"].BackColor = Color.Tomato;
            item["DocReferences"].ForeColor = Color.White;
        }
}

I have tried adding this to the ItemCreated event but it still throws the error.
Can someone throw some light as to what is causing the error - I believe it is something to do with the Ajax process but cannot pinpoint it exactly.

I am at a loss as to how to trobleshoot this.

Regards
Roger

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Mar 2012, 02:09 PM
Hi Roger,

You can specify the Name property for each TableView and can check for the condition as shown below.

aspx:
<MasterTableView Name="Master" CommandItemDisplay="Bottom">
              <DetailTables>
                    <telerik:GridTableView Name="Detail"  CommandItemDisplay="Bottom">
                       .   .   .  .  .

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Master")
    {
         //your code
    }
}

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