R
Richard Wilson
Hi
I'm trying to add a row containing 9 columns to an existing Table on a
web page.
Each new column contains a Text Box Control.
This I've placed in a Button Click Event
When I run the page. The event works fine for the first row. Then on
subsequent clicks all that seems to happen is the 1st new row that was
added is added again (so I lose any data that was in the Text Boxes.
Please help. I think I must be missing something obvious.
Many thanks in advance.
Richard Wilson
RVC
---------------------------------
private void Button1_Click(object sender, System.EventArgs e)
{
// Generate rows and cells.
int numcells = 9;
TableRow r = new TableRow();
for (int i=0; i<numcells; i++)
{
TableCell c = new TableCell();
TextBox textb = new TextBox();
textb.ID = "txtR" + Table1.Rows.Count + "C" + i;
switch(i)
{
case 0:
textb.Width = 30;
break;
case 1:
textb.Width = 50;
break;
case 2:
textb.Width = 40;
break;
case 3:
textb.Width = 40;
break;
case 4:
textb.Width = 40;
break;
case 5:
textb.Width = 50;
break;
case 6:
textb.Width = 80;
break;
case 7:
textb.Width = 80;
break;
case 8:
textb.Width = 80;
break;
}
textb.EnableViewState = true;
c.Controls.Add(textb);
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
I'm trying to add a row containing 9 columns to an existing Table on a
web page.
Each new column contains a Text Box Control.
This I've placed in a Button Click Event
When I run the page. The event works fine for the first row. Then on
subsequent clicks all that seems to happen is the 1st new row that was
added is added again (so I lose any data that was in the Text Boxes.
Please help. I think I must be missing something obvious.
Many thanks in advance.
Richard Wilson
RVC
---------------------------------
private void Button1_Click(object sender, System.EventArgs e)
{
// Generate rows and cells.
int numcells = 9;
TableRow r = new TableRow();
for (int i=0; i<numcells; i++)
{
TableCell c = new TableCell();
TextBox textb = new TextBox();
textb.ID = "txtR" + Table1.Rows.Count + "C" + i;
switch(i)
{
case 0:
textb.Width = 30;
break;
case 1:
textb.Width = 50;
break;
case 2:
textb.Width = 40;
break;
case 3:
textb.Width = 40;
break;
case 4:
textb.Width = 40;
break;
case 5:
textb.Width = 50;
break;
case 6:
textb.Width = 80;
break;
case 7:
textb.Width = 80;
break;
case 8:
textb.Width = 80;
break;
}
textb.EnableViewState = true;
c.Controls.Add(textb);
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}