I this this will be solve the above Problem...
//Code Behind File Write one Function and Call it in Page Load...
public void getTable()
{
Table table = new Table();
table.ID = "Table1";
table.BorderStyle = BorderStyle.Solid;
Page.Form.Controls.Add(table);
// Now iterate through the table and add your controls
int totRow = 2;
int totCol = 4;
for (int i = 0; i < totRow; i++)
{
TableRow row = new TableRow();
for (int j = 0; j < totCol; j++)
{
TableCell cell = new TableCell();
TextBox tb = new TextBox();
// Set a unique ID for each TextBox added
tb.ID = "TextBoxRow_" + i + "Col_" + j;
tb.Attributes.Add("runat", "Server");
tb.Attributes.Add("OnFocusOut", "processText()");
//tb.EnableViewState = false;
tb.MaxLength = 128;
HiddenField hf = new HiddenField();
hf.ID = "HF_" + i + "Col_" + j;
hf.Value = (10 * (i+1)).ToString();
cell.Controls.Add(hf);
cell.Controls.Add(tb);
// Add the TableCell to the TableRow
row.Cells.Add(cell);
}
TableCell celltot = new TableCell();
TextBox tbTot = new TextBox();
tbTot.ID = "TotalRow_" + i + "Col_" + (totCol).ToString();
// tbTot.Attributes.Add("runat", "Server");
//tbTot.Attributes.Add("OnFocusOut", "processText()");
//tbTot.EnableViewState = false;
tbTot.MaxLength = 128;
tbTot.ReadOnly = true;
celltot.Controls.Add(tbTot);
row.Cells.Add(celltot);
// Add the TableRow to the Table
table.Rows.Add(row);
}
TableRow Grow = new TableRow();
Grow.HorizontalAlign = HorizontalAlign.Right;
TableCell Gcelltot = new TableCell();
Label lbl = new Label();
lbl.Text = "Total: ";
Gcelltot.Controls.Add(lbl);
TextBox GtbTot = new TextBox();
Gcelltot.ColumnSpan = 5;
GtbTot.ID = "GTotal";
GtbTot.MaxLength = 128;
GtbTot.ReadOnly = true;
Gcelltot.Controls.Add(GtbTot);
Grow.Cells.Add(Gcelltot);
// Add the Gcelltot to the Table
table.Rows.Add(Grow);
}
// Create Java Script Like
function processText() {
var Gtotal = 0;
var totRows = document.getElementById("Table1").rows.length;
for (var i = 0; i < totRows; i++) {
if (i == totRows - 1) {
TBox = document.getElementById("GTotal");
TBox.value = Gtotal;
}
else {
var totCol = document.getElementById("Table1").rows[i].cells.length
var total = 0;
for (var j = 0; j < totCol; j++) {
if (j == totCol - 1) {
TBox = document.getElementById("TotalRow_" + i + "Col_" + (totCol - 1));
TBox.value = total;
Gtotal = Gtotal + total;
}
else {
HBox = document.getElementById("HF_" + i + "Col_" + j);
var hdata = parseFloat(HBox.value);
if (hdata != null && hdata != "") {
TBox = document.getElementById("TextBoxRow_" + i + "Col_" + j);
var data = TBox.value;
if (data != null && data != "") {
total = total + (hdata * parseFloat(data));
}
}
}
}
}
}
}