Creating a footer template and displaying the total in the gridview
----------------------------------------------------------------------
in the gridview column tag adding the following
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Invoice Date" FooterStyle-HorizontalAlign="right">
<ItemTemplate>
<asp:Label ID="lblInvoiceDate" runat="server" Text='<%# Eval("InvoiceDate") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotalText" Font-Bold="true" runat="Server" Text="Total :"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Right" HeaderText="Invoice Value" FooterStyle-HorizontalAlign="right">
<ItemTemplate>
<asp:Label ID="lblInvoiceDate" Font-Bold="true" runat="server" Text='<%# Eval("InvoiceValue","{0:0.00}") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotal" runat="Server" Text="Total :" Font-Bold="true"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
If (e.Row.RowType = DataControlRowType.Footer) Then
'display the total in the footer
Dim lblTotal As Label = CType(e.Row.FindControl("lblTotal"), Label)
Dim dbObj As New dbutil()
Dim qryFmt As String = "SELECT SUM(FFGrandTotal) AS InvoiceValue FROM TTINVVIEW WHERE FFJONO='{0}'"
Dim qry As String = String.Format(qryFmt, Request.QueryString("Value"))
lblTotal.Text = Decimal.Parse(dbObj.ExecuteScalar(qry), Globalization.NumberStyles.AllowDecimalPoint).ToString("0.00")
End If
----------------------------------------------------------------------
in the gridview column tag adding the following
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Invoice Date" FooterStyle-HorizontalAlign="right">
<ItemTemplate>
<asp:Label ID="lblInvoiceDate" runat="server" Text='<%# Eval("InvoiceDate") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotalText" Font-Bold="true" runat="Server" Text="Total :"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Right" HeaderText="Invoice Value" FooterStyle-HorizontalAlign="right">
<ItemTemplate>
<asp:Label ID="lblInvoiceDate" Font-Bold="true" runat="server" Text='<%# Eval("InvoiceValue","{0:0.00}") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotal" runat="Server" Text="Total :" Font-Bold="true"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
If (e.Row.RowType = DataControlRowType.Footer) Then
'display the total in the footer
Dim lblTotal As Label = CType(e.Row.FindControl("lblTotal"), Label)
Dim dbObj As New dbutil()
Dim qryFmt As String = "SELECT SUM(FFGrandTotal) AS InvoiceValue FROM TTINVVIEW WHERE FFJONO='{0}'"
Dim qry As String = String.Format(qryFmt, Request.QueryString("Value"))
lblTotal.Text = Decimal.Parse(dbObj.ExecuteScalar(qry), Globalization.NumberStyles.AllowDecimalPoint).ToString("0.00")
End If
No comments:
Post a Comment