private void AddNewRow() { 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++) { TextBox txtEmpCode = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[1].FindControl("txtEmpCode"); TextBox txtHours = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[2].FindControl("txtHours"); TextBox txtCode = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[3].FindControl("txtCode"); drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["RowNumber"] = i + 1; dtCurrentTable.Rows[i - 1]["empl_code"] = txtEmpCode.Text; dtCurrentTable.Rows[i - 1]["hours"] = txtHours.Text; dtCurrentTable.Rows[i - 1]["awr_code"] = txtCode.Text.ToUpper(); rowIndex++; } dtCurrentTable.Rows.Add(drCurrentRow); ViewState["CurrentTable"] = dtCurrentTable; grvStudentDetails.DataSource = dtCurrentTable; grvStudentDetails.DataBind(); } } else { Response.Write("ViewState is null"); } SetPreviousData(); }
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)