in above image . its dynamically created table with textbox in a pop up


, here if the user adds first value in 1 year leasing cost or capital reserves ... the third row total capex has to get populated with sum of above two rows. this is a dynamically created table structure.
below is the code which creates above dynamic table
private void CreateDynamicTable()
{
try
{
this.pnlPopup.FindControl("PlaceHolder1").Controls.Clear();
// Fetch the number of Rows and Columns for the table
// Create a Table and set its properties
Table tbl = new Table();
tbl.ID = "tblDynamic";
tbl.BorderWidth = 1;
tbl.GridLines = (GridLines)3; // no. 3 means --> GridLines="Both"
tbl.Attributes["runat"] = "server";
// Add the table to the placeholder control
for (int i = 0; i < 3; i++)
{
TableRow tr = new TableRow();
TableCell tc_1 = new TableCell();
Label lbl = new Label();
if (i == 0)
{
tc_1.ID ="dyn"+ i + "," + 0;
lbl.ID = "lblRow_" + i + "Col_" + 00;
lbl.Text = "CapEx";
}
else if (i == 1)
{
tc_1.ID = "dyn" + i + "," + 0;
lbl.ID = "lblRow_" + i + "Col_" + 00;
lbl.Text = "Leasing Costs";
}
else if (i == 2)
{
tc_1.ID = "dyn" + i + "," + 0;
lbl.ID = "lblRow_" + i + "Col_" + 00;
lbl.Text = "Capital Reserves";
}
tc_1.Controls.Add(lbl);
tr.Cells.Add(tc_1);
for (int j = 0; j < Convert.ToInt32(txtValperiod.Text); j++)
{
TableCell tc = new TableCell();
TextBox txtBox = new TextBox();
Label lbl_1 = new Label();
if (i == 0 )
{
lbl_1.Text = j + 1 + "year";
tc.ID = "dy" + i + "," + j;
tc.Controls.Add(lbl_1);
tr.Cells.Add(tc);
}
else
{
// Set a unique ID for each TextBox added
txtBox.ID = "TextBoxRow_" + i + "Col_" + j;
txtBox.Width = 50;
tc.ID = "dy" + i + "," + j;
// Add the control to the TableCell
tc.Controls.Add(txtBox);
// Add the TableCell to the TableRow
tr.Cells.Add(tc);
}
}
// Add the TableRow to the Table
tbl.Rows.Add(tr);
}
this.pnlPopup.FindControl("PlaceHolder1").Controls.Add(tbl);
// This parameter helps determine in the LoadViewState event,
// whether to recreate the dynamic controls or not
ViewState["dynamictable"] = true;
}
catch (Exception ex)
{
}
}