User61956409 posted
Hi Omar27,
eed to show under the gridview the total of all the prices of the products
To achieve the requirement, you can refer to the following sample code.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" ShowFooter="true" OnRowDataBound="GridView1_RowDataBound" FooterStyle-CssClass="">
<Columns>
<asp:BoundField DataField="pname" HeaderText="Name" />
<asp:BoundField DataField="pprice" HeaderText="Price" />
<asp:BoundField DataField="pquantity" HeaderText="Quantity" />
</Columns>
</asp:GridView>
int total = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Increment the running totals
total += Convert.ToInt32(e.Row.Cells[1].Text) * Convert.ToInt32(e.Row.Cells[2].Text);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
//Display the summary data in the footer
e.Row.Cells[1].Text = "Total";
e.Row.Cells[2].Text = total.ToString();
}
}
Test Result:

With Regards,
Fei Han