2
Answers

How to add asp table rows at run time

ramya g

ramya g

15y
7.9k
1

Please let me know how to dynamically add asp table rows on a button click. Also the table cells should contain text boxes.
Details: I want to have a table row with 9 columns and the columns should have text boxes everytime i click a button. Like this i should be able to generate one row with 9 coulmns on each click.
 
Thanks,
Ramya
Answers (2)
0
ramya g

ramya g

NA 5 0 15y

I think i am not being very clear. I have a drop down list and if i select a item and click the button, it should add a row to the exiting table. Next time when i select one more item from the drop down list and click the button, it should append the row. I have this following code which is adding a row with 9 columns at the first button click.but for the next button click , it is over writing on the previously added row. please help me out.
protected
void btnOK_Click(object sender, EventArgs e)
{

TableRow
tr = new TableRow();
TableCell firstcell = new TableCell();
TextBox firstcelltxtbox = new TextBox();
firstcelltxtbox.Text =
this.ddlDepartments.Text;
firstcell.Controls.Add(firstcelltxtbox);
tr.Cells.Add(firstcell);
//add cells to the new row
for (int i = 0; i < 8; )
{
TableCell tc = new TableCell();
TextBox txtbox = new TextBox();
tc.Controls.Add(txtbox);
tr.Cells.Add(tc);
i++;
}
// add row to the existing table

this.TableMyTimeSheet.Rows.Add(tr);

}
0
ramya g

ramya g

NA 5 0 15y

Thanks Nikhil,
Can you please let me know how to add just one row with 9 columns each time i click the button.
Thanks,
Ramya