dear friends,
I have added dynamic rows and columns with textbox in gridview, but not able to retrieve the values.
code sample for column add dynamically
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
DataTable dtS = dtCurrentTable;
string colName = "NewColumn" + colCount;
dtS = AddColumn(dtS, colName);
BindGrid(dtS);
colCount++;
// Rows
foreach (GridViewRow row in this.GrdDynamic.Rows)
{
for (int i = initialCount; i < row.Cells.Count; i++)
{
TableCell tc = row.Cells[i];
TextBox textBox = new TextBox();
textBox.ID = "txtData" + i;
textBox.Text = dtS.Rows[0].Field<string>(i);
textBox.EnableViewState = true;
textBox.Attributes.Add("runat", "server");
tc.Controls.Add(textBox);
}
}
code sample for row add,
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
TextBox TextBoxName =
(TextBox)grvStudentDetails.Rows[rowIndex].Cells[1].FindControl("txtCol1");
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["RowNum"] = i + 1;
dtCurrentTable.Rows[i - 1]["Col1"] = TextBoxName.Text;
rowIndex++;
}
dtCurrentTable.Rows.Add(drCurrentRow);
ViewState["CurrentTable"] = dtCurrentTable;
grvStudentDetails.DataSource = dtCurrentTable;
grvStudentDetails.DataBind();
}
}
Please help on this.