i am trying to do column wise addition in Gridview but couldn't.
like i am filling gridview from store procedure which gives these values .
DateTime 10Quantity 20Quantity 30Quantity 10Amount 20Amount 30Amount GrandTotal
03/10/2015 792 0 594 7920 0 17820 25740
03/10/2015 332 3 194 9990 0 28220 38739
Expected:
DateTime 10Quantity 20Quantity 30Quantity 10Amount 20Amount 30Amount GrandTotal
03/10/2015 792 0 594 7920 0 17820 25740
03/10/2015 332 3 194 9990 0 28220 38739
Totals 1124 3 788 17910 0 46040 64479
i want a new row 'Totals' which should represent total for each column i.e. addition.
Code:
<asp:GridView ID="GridViewDenominationsWiseTransactions" runat="server" Width="100%" AutoGenerateColumns="False"
ShowFooter="True" OnRowDataBound="GridViewDenominationsWiseTransactions_RowDataBound" CssClass="table table-hover table-striped table-bordered">
<Columns>
<asp:BoundField HeaderText="Date" DataField="DateTime" DataFormatString="{0:dd/MMM/yyyy hh:mm}" HtmlEncode="false" ItemStyle-CssClass="visible-desktop"
HeaderStyle-CssClass="visible-desktop">
<HeaderStyle CssClass="visible-desktop"></HeaderStyle>
<ItemStyle Width="11%" />
</asp:BoundField>
<%-- <asp:BoundField HeaderText="Conductor Name" DataField="ConductorName" ItemStyle-CssClass="visible-desktop"
HeaderStyle-CssClass="visible-desktop">
<HeaderStyle CssClass="visible-desktop"></HeaderStyle>
<ItemStyle Width="8%"></ItemStyle>
</asp:BoundField>--%>
<asp:BoundField HeaderText="10 Quantity" DataField="10Quantity" ItemStyle-CssClass="visible-desktop"
HeaderStyle-CssClass="visible-desktop">
<HeaderStyle CssClass="visible-desktop"></HeaderStyle>
<ItemStyle Width="8%" CssClass="visible-desktop"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="20 Quantity" DataField="20Quantity" ItemStyle-CssClass="visible-desktop"
HeaderStyle-CssClass="visible-desktop">
<HeaderStyle CssClass="visible-desktop"></HeaderStyle>
<ItemStyle Width="8%" CssClass="visible-desktop"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="30 Quantity" DataField="30Quantity" ItemStyle-CssClass="visible-desktop"
HeaderStyle-CssClass="visible-desktop">
<HeaderStyle CssClass="visible-desktop"></HeaderStyle>
<ItemStyle Width="8%" CssClass="visible-desktop"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="10 Amount" DataField="10Amount" ItemStyle-CssClass="visible-desktop"
HeaderStyle-CssClass="visible-desktop">
<HeaderStyle CssClass="visible-desktop"></HeaderStyle>
<ItemStyle Width="8%" CssClass="visible-desktop"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="20 Amount" DataField="20Amount" ItemStyle-CssClass="visible-desktop"
HeaderStyle-CssClass="visible-desktop">
<HeaderStyle CssClass="visible-desktop"></HeaderStyle>
<ItemStyle Width="8%" CssClass="visible-desktop"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="30 Amount" DataField="30Amount" ItemStyle-CssClass="visible-desktop"
HeaderStyle-CssClass="visible-desktop">
<HeaderStyle CssClass="visible-desktop"></HeaderStyle>
<ItemStyle Width="8%" CssClass="visible-desktop"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="GrandTotal" DataField="GrandTotal" ItemStyle-CssClass="visible-desktop"
HeaderStyle-CssClass="visible-desktop">
<HeaderStyle CssClass="visible-desktop"></HeaderStyle>
<ItemStyle Width="13%" CssClass="visible-desktop"></ItemStyle>
</asp:BoundField>
</Columns>
</asp:GridView>
SP;
ALTER PROCEDURE [dbo].[ReportDenominationWiseTransaction] '03-10-2015', '03-10-2015'
@FromDate date,
@ToDate date
AS
BEGIN
with myquery ([DateTime],amount,Quantity)
as
(
select Convert(varchar(20),serverdatetime,101) 'DateTime',amount,1 'Quantity'
from tickets
WHERE CONVERT(DATE,ServerDateTime) BETWEEN @FromDate and @ToDate
)
select *, 10 * c.[10Quantity] '10Amount',20 * c.[20Quantity] '20Amount',30 * c.[30Quantity] '30Amount',((10 * c.[10Quantity])+(20 * c.[20Quantity])+(30 * c.[30Quantity]))'GrandTotal' from (
SELECT DateTime,[10] AS '10Quantity', [20] AS '20Quantity', [30] AS '30Quantity'
FROM
(SELECT [DateTime], amount,quantity
FROM myquery) p
PIVOT
(
COUNT ([Quantity])
FOR [Amount] IN
( [10], [20], [30])
) AS pvt
) as c
END
i must do it from front end i.e. gridview
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…