1. Define the "table" variable as global like "Table table;".
2. In the binding function change the following lines from
Table table = new Table();
table.Attributes["class"] = "dynamic_table";
studentList.Controls.Add(table);
to
table = new Table();
table.ID = "DynamicTable";
table.Attributes["class"] = "dynamic_table";
studentList.Controls.Add(table);
3. Now in your button click get the table from the studentList like
Table table = (Table)studentList.FindControl("DynamicTable");
4. To access the controls in the table
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Label lblId = (Label)table.FindControl("lblId_" + i);
}
It has helped me retrieve the value of the control and hope this helps you too.