本文介绍了显示错误列ID不允许空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    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();
    }





当我点击添加按钮Iam调用此方法时,我有gridview。这个方法的议程是添加新行>但我得到错误列'产品'不允许空值。

推荐答案


这篇关于显示错误列ID不允许空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 07:08