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

NestedViewTemplate & Grid - Group Footers

1 Answer 14 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mehmet
Top achievements
Rank 1
Mehmet asked on 14 Jul 2014, 12:58 AM
Hi there,

I am trying to make the exact demo as http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/grouping/group-footers/defaultcs.aspx for a nestedviewtemplate , however, it doesnt work. 
I do basically have a grid and another grid as a nested one into the master, and I would like to make a footer total calculation in the nested grid template.
Any idea ?
thank you

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 15 Jul 2014, 11:11 AM
Hi Mehmet,

Please take a look at the sample code snippet which shows NestedViewTemplate with GroupFooters.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" AllowPaging="True" ShowFooter="true" ShowGroupPanel="true" OnItemCommand="RadGrid1_ItemCommand" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView DataKeyNames="OrderID" HierarchyLoadMode="Client" ShowGroupFooter="true">
        <GroupFooterTemplate>
                 Total Freight:
            <asp:Label ID="lblFreight" runat="server" Text='<%# Eval("Freight") %>'>
            </asp:Label>
                 Total ShipVia:
            <asp:Label ID="lblShipVia" runat="server" Text='<%# Eval("ShipVia") %>'>
            </asp:Label>
                Total price:
            <asp:Label ID="lbltotal" runat="server" Text='<%# Eval("TotalPriceResult") %>'>
            </asp:Label>
        </GroupFooterTemplate>
        <Columns>
            <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" UniqueName="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Freight" HeaderText="Freight" UniqueName="Freight" Aggregate="Sum">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipVia" HeaderText="ShipVia" UniqueName="ShipVia" Aggregate="Sum">
            </telerik:GridBoundColumn>
            <telerik:GridCalculatedColumn HeaderText="Total Price" UniqueName="TotalPrice" DataType="System.Double" DataFields="Freight, ShipVia" Expression="{0}*{1}" FooterText="Total : " Aggregate="Sum">
            </telerik:GridCalculatedColumn>
        </Columns>
        <NestedViewSettings>
            <ParentTableRelation>
                <telerik:GridRelationFields DetailKeyField="OrderID" MasterKeyField="OrderID" />
            </ParentTableRelation>
        </NestedViewSettings>
        <NestedViewTemplate>
            <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="False" PageSize="5" ShowFooter="true" ShowGroupPanel="true" AllowPaging="True" OnNeedDataSource="RadGrid2_NeedDataSource">
                <MasterTableView HierarchyLoadMode="Client" ShowGroupFooter="true">
                    <GroupFooterTemplate>
                             Total UnitPrice:
                        <asp:Label ID="lblUnitPrice" runat="server" Text='<%# Eval("UnitPrice") %>'>
                        </asp:Label>
                             Total Quantity:
                        <asp:Label ID="lblQuantity" runat="server" Text='<%# Eval("Quantity") %>'>
                        </asp:Label>
                            Total price:
                        <asp:Label ID="lblTotalPrice" runat="server" Text='<%# Eval("TotalPriceResult") %>'>
                        </asp:Label>
                    </GroupFooterTemplate>
                    <Columns>
                        <telerik:GridBoundColumn HeaderText="UnitPrice" DataField="UnitPrice" UniqueName="UnitPrice" Aggregate="Sum">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn HeaderText="Quantity" DataField="Quantity" UniqueName="Quantity" Aggregate="Sum">
                        </telerik:GridBoundColumn>
                        <telerik:GridCalculatedColumn HeaderText="Total Price" UniqueName="TotalPrice" DataType="System.Double" DataFields="UnitPrice, Quantity" Expression="{0}*{1}" FooterText="Total : " Aggregate="Sum">
                        </telerik:GridCalculatedColumn>
                    </Columns>
                </MasterTableView>
                <ClientSettings AllowDragToGroup="true">
                </ClientSettings>
            </telerik:RadGrid>
        </NestedViewTemplate>
    </MasterTableView>
    <ClientSettings AllowDragToGroup="true">
    </ClientSettings>
</telerik:RadGrid>

C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = GetDataTable("SELECT OrderID, Freight, ShipVia FROM Orders");
}
 
protected void RadGrid2_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    GridDataItem parentItem = ((sender as RadGrid).NamingContainer as GridNestedViewItem).ParentItem as GridDataItem;
    (sender as RadGrid).DataSource = GetDataTable("SELECT UnitPrice, Quantity,OrderID FROM [Order Details] where OrderID='" + parentItem.GetDataKeyValue("OrderID").ToString() + "' ");
}
 
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExpandCollapseCommandName && !e.Item.Expanded)
    {
        GridDataItem parentItem = e.Item as GridDataItem;
        RadGrid rg = parentItem.ChildItem.FindControl("RadGrid2") as RadGrid;
        rg.Rebind();
    }
}
public DataTable GetDataTable(string query)
{
    String ConnString = ConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString;
    SqlConnection conn = new SqlConnection(ConnString);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand(query, conn);
 
    DataTable myDataTable = new DataTable();
 
    conn.Open();
    try
    {
        adapter.Fill(myDataTable);
    }
    finally
    {
        conn.Close();
    }
 
    return myDataTable;
}

Thanks,
Princy
Tags
Grid
Asked by
Mehmet
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or