views:

820

answers:

1

Hi,

I've the following code which is used to display ItemID, Name, and Price via SQLDATASOURCE. How is it possible to get the SUM of the values in the Price column and display it in the footer?

<asp:GridView ID="GridView2" runat="server" ShowFooter="true" AutoGenerateColumns="False" DataKeyNames="ItemID"
    DataSourceID="SqlDataSource2" Style="position: relative"  >
    <Columns>
        <asp:BoundField DataField="ItemID" HeaderText="ItemID" InsertVisible="False" ReadOnly="True"
            SortExpression="ItemID" />
        <asp:BoundField DataField="Name" HeaderText="Name" FooterText="Total" FooterStyle-Font-Bold="true" SortExpression="Name" />
        <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
        <ItemTemplate>
    </Columns>
</asp:GridView>

Your help is greatly appeciated.

thank you,

+1  A: 
((Label)GridView1.FooterRow.Cells[1].FindControl("Label2")).Text = 
myDataSet.Tables[0].Compute("sum(unitsinstock)", "").ToString();

Get more details here: http://programming.top54u.com/post/ASPNet-20-GridView-Compute-Column-Sum-using-C-sharp.aspx

NinethSense