protected void GenerateTableOnDelete(int rowsCount, int deleteID)
{
rowsCount--;
Table table = new Table();
table.ID = "Table1";
PlaceHolder1.Controls.Add(table);
const int colsCount = 6;
TableHeaderRow header = new TableHeaderRow();
TableHeaderCell headerTableCell1 = new TableHeaderCell();
headerTableCell1.Text = "Item Name";
header.Cells.Add(headerTableCell1);
table.Rows.Add(header);
for (int i = 0, k = 0; i < rowsCount; i++)
if (i < deleteID)
k = i; else
k = i - 1;
if (deleteID != i)
TableRow row = new TableRow();
row.ID = "Row_" + k;
for (int j = 0; j < colsCount; j++)
if (j == colsCount - 6)
TableCell cell = new TableCell();
DropDownList ddl = new DropDownList();
ds = fetchStates();
ddl.DataSource = ds.Tables[0];
ddl.DataValueField = "EmpId";
ddl.DataTextField = "EmpName";
ddl.DataBind();
ddl.ID = "DropDownListRow_" + k + "Col_" + j;
cell.Controls.Add(ddl);
row.Cells.Add(cell);
} }
table.Rows.Add(row);
SetPreviousDataOnDelete(rowsCount, colsCount, deleteID);
ViewState["RowsCount"] = rowsCount;
}
Table table = (Table)this.Page.FindControl("PlaceHolder1").FindControl("Table1"); // **** if (table != null) {
private void SetPreviousData(int rowsCount, int colsCount)
Table table = (Table)this.Page.FindControl("ContentPlaceHolder1").FindControl("Table1");
for (int i = 0; i < rowsCount; i++)
DropDownList ddl = (DropDownList)table.Rows[i+1].Cells[j].FindControl("DropDownListRow_" + i + "Col_" + j);
ddl.Text = Request.Form["DropDownListRow_" + i + "Col_" + j];
} } } }