public void AddNewRowToGrid() { int rowIndex = 0; if (ViewState["CurrentTable"] != null) { DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { //extract the TextBox values TextBox box1 = (TextBox)gvAnswer.Rows[rowIndex].Cells[1].FindControl("txtAnswer"); drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["RowNumber"] = i + 1; drCurrentRow["Column1"] = box1.Text; rowIndex++; } //add new row to DataTable // dtCurrentTable.Rows.Add(drCurrentRow); //Store the current data to ViewState dtCurrentTable.Rows.Add(drCurrentRow); ViewState["CurrentTable"] = dtCurrentTable; //Rebind the Grid with the current data gvAnswer.DataSource = dtCurrentTable; gvAnswer.DataBind(); } } else { Response.Write("ViewState is null"); } //Set Previous Data on Postbacks SetPreviousData(); }
i have created dynamic text box at button click event.everytime i have called AddNewRowToGrid() () to button click event.
now i have added 3 blank textbox.now i have enter value in 1st text box and click button .then new row have generated but 1st text box value was clearing.but i want to get that value...
u can see above highlighted code ...if any one have any idea let me know as earlier as possible.
Thanks,
Khushboo Nayak.