Hi shal,
Please refer below sample.
HTML
<asp:GridView ID="gvCalulation" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:BoundField HeaderText="Process" DataField="Process" />
<asp:BoundField HeaderText="%" DataField="%" />
<asp:BoundField HeaderText="Value" DataField="Value" />
</Columns>
</asp:GridView>
Namespace
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("Process"),
new DataColumn("%", typeof(int)),
new DataColumn("Value", typeof(int))
});
dt.Rows.Add("A", 99);
dt.Rows.Add("B", 97);
dt.Rows.Add("C", 99);
for (int i = dt.Rows.Count - 1; i >= 0; i--)
{
DataRow dr = dt.Rows[i];
if (i == dt.Rows.Count - 1)
{
dr["Value"] = (1000 / Convert.ToDecimal(dr["%"])) * 100;
}
else
{
dr["Value"] = (Convert.ToDecimal(dt.Rows[i + 1]["Value"]) / Convert.ToDecimal(dr["%"])) * 100;
}
}
this.gvCalulation.DataSource = dt;
this.gvCalulation.DataBind();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("Process"), New DataColumn("%", GetType(Integer)), New DataColumn("Value", GetType(Integer))})
dt.Rows.Add("A", 99)
dt.Rows.Add("B", 97)
dt.Rows.Add("C", 99)
For i As Integer = dt.Rows.Count - 1 To 0 Step -1
Dim dr As DataRow = dt.Rows(i)
If i = dt.Rows.Count - 1 Then
dr("Value") = (1000 / Convert.ToDecimal(dr("%"))) * 100
Else
dr("Value") = (Convert.ToDecimal(dt.Rows(i + 1)("Value")) / Convert.ToDecimal(dr("%"))) * 100
End If
Next
Me.gvCalulation.DataSource = dt
Me.gvCalulation.DataBind()
End Sub
Screenshot