int cnt = 0;
foreach (string item in valueslist)
{
TableRow tr = new TableRow();
TableCell tc = new TableCell();
TableCell col2 = new TableCell();
Label lb = new Label();
lb.Text = item;
TextBox tb1 = new TextBox();
tb1.Style["text-align"] = "Right";
tb1.ID = "txt" + k;
tb1.Text = "0";
tb1.EnableViewState = true;
tb1.AutoPostBack = true;
tb1.TextChanged += new EventHandler(tb1_TextChanged);
tb1.ID = "Tab" + cnt.ToString();
tb1.TabIndex = (short)(cnt);
cnt++;
tb1.Text = "0";
string ids = string.Format("lb{0}", k);
lb.ID = ids;
tc.Controls.Add(lb);
col2.Controls.Add(tb1);
tr.Controls.Add(tc);
tr.Controls.Add(col2);
table.Controls.Add(tr);
k++;
}
The problem is your
cnt variable. Always be 0.
Hope it helps