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

custom aggregate for grid and table

2 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
moegal
Top achievements
Rank 1
moegal asked on 31 Oct 2012, 10:35 PM
I have a grid with datasource1 and then I have a gridtableview with datasource2 similar to the example "Grid / Several Tables at a Level"both data sources have a column called Price.

Can I create an aggregate that uses the values from both?

If so, can you point me in the right direction.

Thanks, Marty

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Nov 2012, 08:24 AM
Hi,

Please take a look into the sample code snippet I tried to give the aggregate of common column in the Footer of the Second Detail Table. Make sure that you have set the 'Name' property for each GridTableView.

C#:
static int total1 = 0;
static int total2 = 0;
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        if (e.Item.OwnerTableView.Name == "NameOfTheFirstDetailTable")
        {
            GridDataItem dataItem = e.Item as GridDataItem;
            int fieldValue = int.Parse(dataItem["ColumnUniqueName"].Text);
            total1 += fieldValue;
        }
        if (e.Item.OwnerTableView.Name == "NameOfTheSecondDetailTable")
        {
            GridDataItem dataItem = e.Item as GridDataItem;
            int fieldValue = int.Parse(dataItem["ColumnUniqueName"].Text);
            total2 += fieldValue;
        }
    }
    if (e.Item is GridFooterItem)
    {
        GridFooterItem fitem = (GridFooterItem)e.Item;
        if (e.Item.OwnerTableView.Name == "NameOfTheSecondDetailTable")
        {
            fitem["Order2"].Text = "Total Price="+ (total1 + total2).ToString();
        }
    }
}

Thanks,
Shinu.
0
moegal
Top achievements
Rank 1
answered on 01 Nov 2012, 10:00 AM
thanks, I will give it a try!
Tags
Grid
Asked by
moegal
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
moegal
Top achievements
Rank 1
Share this question
or