Hi ucrhlyn,
Refer below code for your reference.
HTML
<asp:GridView runat="server" ID="gvData" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Month" HeaderText="Month" />
<asp:BoundField DataField="Depreciation" HeaderText="Depriciation Expenses" DataFormatString="{0:N2}" />
<asp:BoundField DataField="Accumulated" HeaderText="Accumulate Deprication at Month-End"
DataFormatString="{0:N2}" />
<asp:BoundField DataField="BookValue" HeaderText="Book Value at Month-End" DataFormatString="{0:N2}" />
</Columns>
</asp:GridView>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
DateTime acquiredDate = new DateTime(2019, 09, 01);
DateTime startMonth = new DateTime(2019, 09, 01);
double depreciation = 100;
double slavege = 1.00;
int lifeMonth = 10;
DataTable dt = new DataTable();
dt.Columns.Add("Month");
dt.Columns.Add("Depreciation", typeof(decimal));
dt.Columns.Add("Accumulated", typeof(decimal));
dt.Columns.Add("BookValue", typeof(decimal));
int i = 0;
double depreciationExpense = (depreciation - slavege) / lifeMonth;
double bookValue = depreciation - depreciationExpense;
double newDepreciationExpense = 0;
while (startMonth < acquiredDate.AddMonths(lifeMonth))
{
DataRow dr = dt.NewRow();
dr["Month"] = startMonth.ToString("MMM yyyy");
dr["Depreciation"] = depreciationExpense;
if (i == 0)
{
dr["Accumulated"] = Math.Round(depreciationExpense, 2);
dr["BookValue"] = Math.Round(bookValue, 2);
newDepreciationExpense = depreciationExpense;
}
else
{
newDepreciationExpense = newDepreciationExpense + depreciationExpense;
bookValue = bookValue - depreciationExpense;
dr["Accumulated"] = Math.Round(newDepreciationExpense, 2);
dr["BookValue"] = Math.Round(bookValue, 2);
}
dt.Rows.Add(dr);
startMonth = startMonth.AddMonths(1);
i++;
}
this.gvData.DataSource = dt;
this.gvData.DataBind();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim acquiredDate As DateTime = New DateTime(2019, 9, 1)
Dim startMonth As DateTime = New DateTime(2019, 9, 1)
Dim depreciation As Double = 100
Dim slavege As Double = 1.0
Dim lifeMonth As Integer = 10
Dim dt As DataTable = New DataTable()
dt.Columns.Add("Month")
dt.Columns.Add("Depreciation", GetType(Decimal))
dt.Columns.Add("Accumulated", GetType(Decimal))
dt.Columns.Add("BookValue", GetType(Decimal))
Dim i As Integer = 0
Dim depreciationExpense As Double = (depreciation - slavege) / lifeMonth
Dim bookValue As Double = depreciation - depreciationExpense
Dim newDepreciationExpense As Double = 0
While startMonth < acquiredDate.AddMonths(lifeMonth)
Dim dr As DataRow = dt.NewRow()
dr("Month") = startMonth.ToString("MMM yyyy")
dr("Depreciation") = depreciationExpense
If i = 0 Then
dr("Accumulated") = Math.Round(depreciationExpense, 2)
dr("BookValue") = Math.Round(bookValue, 2)
newDepreciationExpense = depreciationExpense
Else
newDepreciationExpense = newDepreciationExpense + depreciationExpense
bookValue = bookValue - depreciationExpense
dr("Accumulated") = Math.Round(newDepreciationExpense, 2)
dr("BookValue") = Math.Round(bookValue, 2)
End If
dt.Rows.Add(dr)
startMonth = startMonth.AddMonths(1)
i += 1
End While
Me.gvData.DataSource = dt
Me.gvData.DataBind()
End Sub
Screenshot