Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

I've got what should be quite a simple question, I think!

I have a DataGridView that will display details of "Pricing". To display the DataBound DataGridView, we are using the following code.

HTML/ASP
ASP.NET
<asp:GridView ID="grvAgentStats" runat="server" AutoGenerateColumns="False" 
    CellPadding="4" ForeColor="#333333" 
    GridLines="None" style="font-size: 12px" Width="500px" ShowFooter="True">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:BoundField DataField="Result" HeaderText="Result" ItemStyle-Wrap="false" 
            ItemStyle-HorizontalAlign = "Left">
<ItemStyle HorizontalAlign="Left" Wrap="False"></ItemStyle>
        </asp:BoundField>
        <asp:BoundField DataField="Amount" HeaderText="Amount" 
            ItemStyle-HorizontalAlign = "Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
        </asp:BoundField>
        <asp:BoundField DataField="At" HeaderText="" 
            ItemStyle-HorizontalAlign = "Center">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
        </asp:BoundField>
        <asp:BoundField DataField="Fee" HeaderText="Fee" 
            ItemStyle-HorizontalAlign = "Center" DataFormatString="{0:c}" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
        </asp:BoundField>
        <asp:BoundField DataField="Equals" HeaderText="" 
            ItemStyle-HorizontalAlign = "Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
        </asp:BoundField>
        <asp:BoundField DataField="Total" HeaderText="Total" 
            ItemStyle-HorizontalAlign = "Center" DataFormatString="{0:c}" 
            FooterText="0.00" >
        <FooterStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center"></ItemStyle>
        </asp:BoundField>
    </Columns>
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Center"/>
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#EFF3FB"  HorizontalAlign="Center"/>
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#F5F7FB" />
    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
    <SortedDescendingCellStyle BackColor="#E9EBEF" />
    <SortedDescendingHeaderStyle BackColor="#4870BE" />
    </asp:GridView>


Code-behind

VB
Private Sub DatabindResults()
        Dim SQLconn As SqlConnection
        Dim SQLComm As SqlCommand
        Dim SQLDa As SqlDataAdapter
        Dim SQLDs As DataSet
        Dim ADUsername As String = Session.Item("txtUsername")

        Dim Date1 As String = ddlDates.SelectedValue
        Dim ClientName As String = ddlClient.SelectedValue

        SQLconn = New SqlConnection(ConfigurationManager.ConnectionStrings("Connection").ConnectionString)

        SQLComm = New SqlCommand("prcHHGenAgentStats_New", SQLconn)
        SQLComm.CommandType = CommandType.StoredProcedure
        SQLComm.Parameters.AddWithValue("@Variable1", Month)
        SQLComm.Parameters.AddWithValue("@Variable2", ADUsername)
        SQLComm.Parameters.AddWithValue("@Variable3", ClientName)

        SQLDa = New SqlDataAdapter(SQLComm)
        SQLDs = New DataSet()

        SQLDa.Fill(SQLDs, "AgentStats")
        ViewState("AgentStats") = SQLDs

        grvAgentStats.DataSource = SQLDs.Tables(0).DefaultView
        grvAgentStats.DataBind()
    End Sub


As you can see I have the footer row in there but how do I now get it to "SUM" the Total column. I was hoping to do this without using a SQL Query/Stored Procedure.

Any help will be greatly appreciated!!

Thanks,
Jammo :)
Posted

 
Share this answer
 
Comments
JammoD87 2-Aug-12 10:13am    
I did try a few Google Searches, and a search on here but couldn't seem to get what I want.

Managed to figure it out either way!

Thanks for the quick response!! :)
OK. The question asks about a DataGridView (Forms) but answer is for GridView (Web).

Please use these terms correctly so those of us looking for answers can get results grounded in reality.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900