Hi
I am a newbee in asp.net. I want to create a table dynamically. Say there are two buttons 'add row', 'delete row' which calls addRow, deleteRow event handlers. A sample code is given below :
Problem here is when the page is postback, pageLoad is called and the Page doesnt have the updated table information. So addRow doesn't work (row.count will always return 0).
How to solve this problem? I read that ControlState can be used to save states across postbacks. Can I use ControlState? If so, can you please give me an example code.
protected void addRow(object sender, EventArgs e)
{
int count2 = table2.Rows.Cou nt;
TableRow r = new TableRow();
TableCell c = new TableCell();
CheckBox ck = new CheckBox();
c.Controls.Add( ck);
r.Cells.Add(c);
int count = table2.Rows.Cou nt;
table2.Rows.Add (r);
count = table2.Rows.Cou nt;
//throw new Exception("The method or operation is not implemented.");
}
protected void Page_Load(objec t sender, EventArgs e)
{
}
Thanks and Regards
Roopesh
I am a newbee in asp.net. I want to create a table dynamically. Say there are two buttons 'add row', 'delete row' which calls addRow, deleteRow event handlers. A sample code is given below :
Problem here is when the page is postback, pageLoad is called and the Page doesnt have the updated table information. So addRow doesn't work (row.count will always return 0).
How to solve this problem? I read that ControlState can be used to save states across postbacks. Can I use ControlState? If so, can you please give me an example code.
protected void addRow(object sender, EventArgs e)
{
int count2 = table2.Rows.Cou nt;
TableRow r = new TableRow();
TableCell c = new TableCell();
CheckBox ck = new CheckBox();
c.Controls.Add( ck);
r.Cells.Add(c);
int count = table2.Rows.Cou nt;
table2.Rows.Add (r);
count = table2.Rows.Cou nt;
//throw new Exception("The method or operation is not implemented.");
}
protected void Page_Load(objec t sender, EventArgs e)
{
}
Thanks and Regards
Roopesh
Comment