1

我有以下代码,用于通过 SQLDATASOURCE 显示 ItemID、Name 和 Price。如何获得价格列中值的总和并将其显示在页脚中?

<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>

非常感谢您的帮助。

谢谢你,

4

1 回答 1

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

在此处获取更多详细信息:http: //programming.top54u.com/post/ASPNet-20-GridView-Compute-Column-Sum-using-C-sharp.aspx

于 2009-06-06T09:05:46.687 回答