显示错误列ID不允许空值 [英] Dispalying error Column ID Does not allow null values

查看:193
本文介绍了显示错误列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。这个方法的议程是添加新行>但我得到错误列'产品'不允许空值。

推荐答案

查看此链接并验证您犯了什么错误复制代码时。



动态添加和删除ASP.NET GridView中的行 [ ^ ]



问候......
See this link and verify what mistake you made while copying the code.

Dynamically adding and deleting rows from ASP.NET GridView[^]

Regards...


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆