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

custom footer on master table and detail table

2 Answers 401 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Maor
Top achievements
Rank 1
Maor asked on 11 Feb 2013, 11:16 AM
hello
i have two tables and the grid is use them in hirarchi.
iwant to be able  to calculate both tables details on the footer. 
so far i managed to create the master table footer but it fails on calculating detail table. it claims it cant match cell to column header 
any ideas why?

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 11 Feb 2013, 12:14 PM
Hi,

Please check the following sample code snippet I tried to assign Custom footer for two Detail tables and showing the grant total of a field footer in the one of the Detail table footer.

ASPX:
<telerik:RadGrid ID="RadGrid1" ShowFooter="True" DataSourceID="SqlDataSource1" runat="server"
    AutoGenerateColumns="False" " AutoGenerateEditColumn="True"
    OnItemDataBound="RadGrid1_ItemDataBound"
    <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="CustomerID" Name="first"
        HierarchyLoadMode="Client" CommandItemDisplay="Top">  
        <Columns>
            <telerik:GridBoundColumn SortExpression="CustomerID" HeaderText="EmployeeID" HeaderButtonType="TextButton"
                DataField="CustomerID" Resizable="True" Reorderable="True" Aggregate="Count">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn SortExpression="ContactName" HeaderText="First Name" HeaderButtonType="TextButton"
                DataField="ContactName" Resizable="True" Reorderable="True">
            </telerik:GridBoundColumn>
        </Columns>
        <DetailTables>
            <telerik:GridTableView AutoGenerateColumns="false" Caption="Sales per Employee" Name="Second"
                ShowFooter="true"  DataSourceID="SqlDataSource2" Width="100%" CommandItemDisplay="Top">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID">
                    </telerik:GridRelationFields>
                </ParentTableRelation>
                <Columns>
                    <telerik:GridBoundColumn SortExpression="OrderID" UniqueName="Order1" HeaderText="Customer Name"
                        HeaderButtonType="TextButton" DataField="OrderID" Resizable="True" Reorderable="True"
                        Aggregate="Sum">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="ShipName" HeaderText="Country" HeaderButtonType="TextButton"
                        DataField="ShipName" Resizable="True" Reorderable="True">
                    </telerik:GridBoundColumn>
                </Columns>
            </telerik:GridTableView>
            <telerik:GridTableView Caption="Products" Name="Third" AutoGenerateColumns="false" DataSourceID="SqlDataSource3">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID">
                    </telerik:GridRelationFields>
                </ParentTableRelation>
                <Columns>
                    <telerik:GridBoundColumn SortExpression="OrderID" UniqueName="Order2" HeaderText="Customer Name"
                        HeaderButtonType="TextButton" DataField="OrderID" Resizable="True" Reorderable="True">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="ShipName" HeaderText="Country" HeaderButtonType="TextButton"
                        DataField="ShipName" Resizable="True" Reorderable="True">
                    </telerik:GridBoundColumn>
                </Columns>
            </telerik:GridTableView>
        </DetailTables>      
    </MasterTableView
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        if (e.Item.OwnerTableView.Name == "Second") //distinguishing the DetailTable using its name and calculating the footer for the second detail table
        {
 
                GridDataItem dataItem = e.Item as GridDataItem;
                string ID = dataItem["Order1"].Text;
                int fieldValue = int.Parse(dataItem["Order1"].Text);
                total1 += fieldValue;
            }
            if (e.Item.OwnerTableView.Name == "Third")//calculating the footer for the third detail table
            {
                GridDataItem dataItem = e.Item as GridDataItem;
                int fieldValue = int.Parse(dataItem["Order2"].Text);
                total2 += fieldValue;
            }
        }
        if (e.Item is GridFooterItem)
        {
            GridFooterItem fitem = (GridFooterItem)e.Item;           
            if (e.Item.OwnerTableView.Name == "Third")
            {
 
                //showing the sum total of the two detail table in the third table
                fitem["Order2"].Text = "Total Price="+ (total1 + total2).ToString();
            }
        }
}

Please elaborate more if it doesn't help.

Thanks,
Shinu.
0
Maor
Top achievements
Rank 1
answered on 11 Feb 2013, 02:39 PM
ok, got it!
thanks it works fine!!!
Tags
Grid
Asked by
Maor
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Maor
Top achievements
Rank 1
Share this question
or