Hi MohanbabuV,
I have created sample that full fill your requirement.
HTML
<div>
<asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnDataBound"
ShowFooter="true">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="ProductName" HeaderText="Name" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:BoundField DataField="Unit" HeaderText="Unit" />
<asp:TemplateField HeaderText="Total">
<ItemTemplate>
<asp:Label ID="lblTotal" runat="server" />
</ItemTemplate>
<FooterTemplate>
<b>Grand Total: </b>
<asp:Label ID="lblGrandTotal" runat="server" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("Id", typeof(int)),
new DataColumn("ProductName", typeof(string)),
new DataColumn("Price",typeof(int)),
new DataColumn("Unit",typeof(int))
});
dt.Rows.Add(1, "Aniseed Syrup", 10, 10);
dt.Rows.Add(2, "Genen Shouyu", 15, 10);
dt.Rows.Add(3, "Alice Mutton", 39, 10);
dt.Rows.Add(4, "Teatime Biscuits", 12, 10);
gvProducts.DataSource = dt;
gvProducts.DataBind();
}
}
int grandTotal = 0;
protected void OnDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int price = int.Parse(e.Row.Cells[2].Text.Trim());
int unit = int.Parse(e.Row.Cells[3].Text.Trim());
Label total = e.Row.FindControl("lblTotal") as Label;
total.Text = (price * unit).ToString();
grandTotal += int.Parse(total.Text);
}
if (e.Row.RowType == DataControlRowType.Footer)
{
(e.Row.FindControl("lblGrandTotal") as Label).Text = grandTotal.ToString();
}
}
Screenshot
