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

[Solved] Calculated Column in detail grid w/DataFields from Master

1 Answer 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
FTI Dev
Top achievements
Rank 1
FTI Dev asked on 19 Nov 2009, 04:56 AM
I am trying to figure out how I can include/reference a bound column from my master grid in a calculated column in my detail grid.  Is there a fairly straightforward way to accomplish this?  I have tried adding the name of the column from the master grid to the DataFields property in the detail grid's calculated column - no luck.

Any guidance on this would be most appreciated!

Thanks, Bruce

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 24 Nov 2009, 01:11 PM
Hello Bruce,

The scenario you are describing is not supported automatically in RadGrid. You will need to implement it yourself. We can suggest you to use a GridTemplateColumn, where in its ItemTemplate you can have a binding expression referencing a field from the parent GridDataItem:

<ItemTemplate>
    <%# (int)Eval((Container as GridDataItem).OwnerTableView.ParentItem.DataItem, "ParentColumnUniqueName") + 10 %>
</ItemTemplate>

Alternatively, you can use RadGrid's ItemCreated/ItemDataBound events to programmatically reference the parent item:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        int parentValue = (int)DataBinder.Eval(item.OwnerTableView.ParentItem.DataItem, "ParentColumnUniqueName");
        item["DestinationColumnName"].Text = (parentValue + 10).ToString();
    }
}


Regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
FTI Dev
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or