c# - Add subtotals to Gridview & percentage difference -
i have gridview derived sql statement. want display subtotals each column , display overall percentage increase/decrease between 2 date ranges. how go this?
<%@ page title="" language="c#" masterpagefile="~/masterpage.master" autoeventwireup="true" codebehind="sales-comparison.aspx.cs" inherits="towelsrusv3.sales_comparison" %> <asp:content id="content1" contentplaceholderid="contentplaceholder1" runat="server"> <div class="panel panel-info"> <div class="panel-heading"> <h1 class="panel-title text-center">sales comparison</h1> </div> <div class="panel-body"> <div class="row"> <div class="col-lg-8"> <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false" datasourceid="sqldatasource1" cssclass="table table-bordered table-responsive table-striped" onselectedindexchanged="gridview1_selectedindexchanged" showfooter="true"> <columns> <asp:boundfield datafield="orderdate" headertext="orderdate" readonly="true" sortexpression="orderdate" /> <asp:boundfield datafield="total2014" headertext="total2014" readonly="true" sortexpression="total2014" /> <asp:boundfield datafield="total2013" headertext="total2013" readonly="true" sortexpression="total2013" /> <asp:boundfield datafield="difference" headertext="difference" readonly="true" sortexpression="difference" /> </columns> </asp:gridview> <asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:livedatav2connectionstring %>" selectcommand="select table2014.orderdate, isnull(table2014.total,0) total2014, isnull(table2013.total,0) total2013, isnull(table2014.total,0)-isnull(table2013.total,0) difference (select sum(order_header_total.oht_net) total, dateadd(day,0,datediff(d,0,order_header.oh_datetime)) orderdate order_header_total inner join order_header on order_header_total.oht_oh_id = order_header.oh_id (order_header.oh_datetime between '12/01/2014' , '12/31/2014') , order_header.oh_os_id in (1, 6, 4) group dateadd(day,0,datediff(d,0,order_header.oh_datetime))) table2014 left outer join (select sum(order_header_total.oht_net) total, dateadd(year,1,dateadd(day,0,datediff(d,0,order_header.oh_datetime))) orderdate order_header_total inner join order_header on order_header_total.oht_oh_id = order_header.oh_id (order_header.oh_datetime between dateadd(year,-1,'12/01/2014') , dateadd(year,-1,'12/31/2014')) , order_header.oh_os_id in (1, 6, 4) group dateadd(year,1,dateadd(day,0,datediff(d,0,order_header.oh_datetime)))) table2013 on table2013.orderdate = table2014.orderdate order table2014.orderdate"></asp:sqldatasource> </div> </div> </div> </div> </asp:content>
you should able add new column @ end of select statement similar
sum(table_a.col1) + sum(table_b.coly) subtotal
then same sort of thing percentage column figure out how calculate percentage.
Comments
Post a Comment