i'm trying to create a table that it's rows has textboxes to fill and save them in database. for it purpose i need to assign textboxes's id to an array and use return this array for click event of save button but this error occurred! is someone help me to fix it?
private string[][] GenerateTable(int colsCount, int rowsCount)
{
string[][] controls_Array = new string[7][];
//Create the Table and Add it to the Page
Table table = new Table();
table.ID = "Table1";
table.CellSpacing =5;
table.BorderWidth = 0;
Page.Form.Controls.Add(table);
TableColoumnHeader(table,table.Rows);
// Now iterate through the table and add your controls
for (int i = 0; i < rowsCount; i++)
{
TableRow row = new TableRow();
Label lbl = new Label();
lbl.Text = "row"+i.ToString();
///
TableCell TC = new TableCell();
TC.Controls.Add(lbl);
row.Cells.Add(TC);
for (int j = 0; j < colsCount; j++)
{
TableCell cell = new TableCell();
// Add the control to the TableCell
if(j==colsCount-1)
{
CheckBox chkb = new CheckBox();
chkb.ID = "CheckBoxRow_" + i + "Cols_" + j;
cell.Controls.Add(chkb);
controls_Array[j][i] = chkb.ID;
}
else
{
TextBox tb = new TextBox();
// Set a unique ID for each TextBox added
tb.ID = "TextBoxRow_" + i + "Col_" + j;
cell.Controls.Add(tb);
controls_Array[j][i] = tb.ID;// this line where is the mentioned error occurred.
}
// Add the TableCell to the TableRow
row.Cells.Add(cell);
}
// Add the TableRow to the Table
table.Rows.Add(row);
}/**/
return controls_Array;
}