日期:2014-05-17 浏览次数:20504 次
<asp:GridView ID="gvProd" runat="server" DataSourceID="sdsProd" AllowPaging="true" PageSize="20"
OnDataBound="CountTotalPrice" AutoGenerateColumns="false" ShowFooter="true">
<HeaderStyle BackColor="Black" ForeColor="White" Font-Bold="true" />
<FooterStyle BackColor="Black" ForeColor="White" Font-Bold="true" />
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" />
<asp:BoundField DataField="UnitPrice" HeaderText="Price" />
<asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" />
</Columns>
</asp:GridView>
protected void CountTotalPrice(object sender, EventArgs e)
{
decimal totalValue = 0;
foreach (GridViewRow row in gvProd.Rows)
{
decimal price = Decimal.Parse(row.Cells[2].Text);
int count = int.Parse(row.Cells[3].Text);
totalValue += price * count;
}
GridViewRow footer = gvProd.FooterRow;
footer.Cells[0].ColumnSpan = 3;