Refer the sample code.
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Style="font-family: Calibri; font-size: medium">
<Columns>
<asp:TemplateField HeaderText="Functional Currency" HeaderStyle-BackColor="Khaki">
<ItemTemplate>
<asp:Label ID="FunctionalCurrency" runat="server"
Text='<%# Bind("FunctionalCurrency") %>' Width="300"></asp:Label>
</ItemTemplate>
<HeaderStyle BackColor="Khaki"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current year"
ItemStyle-Width="150" HeaderStyle-BackColor="Khaki">
<ItemTemplate>
<asp:TextBox ID="CurrentYear" runat="server" BorderStyle="None" Height="30px"
AutoPostBack="True" OnTextChanged="CurrentYear_TextChanged"></asp:TextBox>
</ItemTemplate>
<HeaderStyle BackColor="Khaki"></HeaderStyle>
<ItemStyle Width="150px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("FunctionalCurrency");
dt.Rows.Add("Gross Profit / Gross");
dt.Rows.Add("Depreciation/Amortization");
dt.Rows.Add("Operating Income (EBIT)");
dt.Rows.Add("Total Interest Expense");
dt.Rows.Add("Net Income");
dt.Rows.Add("Cash Flow from Operations");
dt.Rows.Add("Total");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void CurrentYear_TextChanged(object sender, EventArgs e)
{
(GridView1.Rows[6].FindControl("CurrentYear") as TextBox).Text = this.CalculateTotal().ToString("N2");
}
private decimal CalculateTotal()
{
decimal eBit;
decimal.TryParse(((GridView1.Rows[2].FindControl("CurrentYear") as TextBox).Text), out eBit);
decimal interestExpense;
decimal.TryParse(((GridView1.Rows[3].FindControl("CurrentYear") as TextBox).Text), out interestExpense);
decimal cashFlow;
decimal.TryParse(((GridView1.Rows[5].FindControl("CurrentYear") as TextBox).Text), out cashFlow);
if (cashFlow == 0)
{
cashFlow = 1;
}
return ((eBit + interestExpense) / cashFlow);
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As Data.DataTable = New Data.DataTable()
dt.Columns.Add("FunctionalCurrency")
dt.Rows.Add("Gross Profit / Gross")
dt.Rows.Add("Depreciation/Amortization")
dt.Rows.Add("Operating Income (EBIT)")
dt.Rows.Add("Total Interest Expense")
dt.Rows.Add("Net Income")
dt.Rows.Add("Cash Flow from Operations")
dt.Rows.Add("Total")
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
Protected Sub CurrentYear_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
TryCast(GridView1.Rows(6).FindControl("CurrentYear"), TextBox).Text = Me.CalculateTotal().ToString("N2")
End Sub
Private Function CalculateTotal() As Decimal
Dim eBit As Decimal
Decimal.TryParse((TryCast(GridView1.Rows(2).FindControl("CurrentYear"), TextBox).Text), eBit)
Dim interestExpense As Decimal
Decimal.TryParse((TryCast(GridView1.Rows(3).FindControl("CurrentYear"), TextBox).Text), interestExpense)
Dim cashFlow As Decimal
Decimal.TryParse((TryCast(GridView1.Rows(5).FindControl("CurrentYear"), TextBox).Text), cashFlow)
If cashFlow = 0 Then
cashFlow = 1
End If
Return ((eBit + interestExpense) / cashFlow)
End Function
Screenshot