private void AddNewRow() { int rowIndex = 0; if (ViewState["table1"] != null) { DataTable dtCurrentTable = (DataTable)ViewState["table1"]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { oreach (System.Data.DataColumn col in dtCurrentTable.Columns) col.ReadOnly = false; DropDownList ddltype = (DropDownList)gvFormula.Rows[rowIndex].Cells[1].FindControl("ddltype"); DropDownList ddlproduct = (DropDownList)gvFormula.Rows[rowIndex].Cells[2].FindControl("ddlproduct"); TextBox txtwt = (TextBox)gvFormula.Rows[rowIndex].Cells[3].FindControl("txtWeight"); drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["RowNumber"] = i + 1; dtCurrentTable.Rows[i - 1]["product"] = ddlproduct.SelectedItem.Text; dtCurrentTable.Rows[i - 1]["weight"]= txtwt.Text; rowIndex++; } dtCurrentTable.Rows.Add(drCurrentRow); //Error " Column 'Product' does not allow nulls." ViewState["table1"] = dtCurrentTable; gvFormula.DataSource = dtCurrentTable; gvFormula.DataBind(); } } else { Response.Write("ViewState is null"); } SetPreviousData(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)