Refer this code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
<asp:BoundField DataField="AR" HeaderText="AR" ItemStyle-Width="150" />
<asp:BoundField DataField="Maned" HeaderText="Maned" ItemStyle-Width="150" />
<asp:BoundField DataField="Dager" HeaderText="Dager" ItemStyle-Width="150" />
<asp:BoundField DataField="SkipUtgang" HeaderText="SkipUtgang" ItemStyle-Width="150" />
<asp:BoundField HeaderText="Total" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
C#:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[5] { new DataColumn("Id", typeof(int)),
new DataColumn("Ar", typeof(int)),
new DataColumn("Maned", typeof(string)),
new DataColumn("Dager",typeof(int)),
new DataColumn("SkipUtgang", typeof(int))});
dt.Rows.Add(1, 2014, "January", 31, 797);
dt.Rows.Add(1, 2014, "February", 38, 788);
dt.Rows.Add(1, 2014, "Mars", 31, 779);
GridView1.DataSource = dt;
GridView1.DataBind();
for (int i = 0; i < this.GridView1.Rows.Count - 1; i++)
{
double skipUtgang1 = Convert.ToDouble(this.GridView1.Rows[i].Cells[4].Text);
double skipUtgang2 = Convert.ToDouble(this.GridView1.Rows[i + 1].Cells[4].Text);
int monthDays = Convert.ToInt32(this.GridView1.Rows[i + 1].Cells[3].Text);
double totoal = (skipUtgang1 * skipUtgang2) * monthDays;
this.GridView1.Rows[i].Cells[5].Text = totoal.ToString();
}
}
}
Image:
The last row total is empty because you have not provided the next month SkipUtgang value.
Thank You.