【发布时间】:2017-02-24 06:42:11
【问题描述】:
这是页面加载,我在数据表中创建两列,并使用下拉列表连接数据库:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("product_name"), new DataColumn("Quantity") });
ViewState["sales"] = dt;
GridView1.DataBind();
txt_productname.DataSource = sic.get_product_name_for_textbox();
txt_productname.DataTextField = "product_name";
txt_productname.DataValueField = "product_id";
txt_productname.DataBind();
txt_customername.DataSource = sic.get_customer_name_for_textbox();
txt_customername.DataTextField = "customer_name";
txt_customername.DataValueField = "customer_id";
txt_customername.DataBind();
}
代码端这是一个临时数据网格:
protected void btn_insert_Click(object sender, EventArgs e)
if (string.IsNullOrWhiteSpace(txt_productname.Text) ||string.IsNullOrWhiteSpace(txt_quantity.Text))
{
Response.Write("<script LANGUAGE='JavaScript'>alert('NotAllowNull') </script>");
}
else
{
DataTable dt = null;
if (Session["DataTable"] != null)
dt = (DataTable)Session["DataTable"];
else
{
}
dt.Rows.Add(txt_productname.SelectedValue.ToString());
dt.Rows.Add(txt_quantity.Text);
GridView1.DataSource = dt;
GridView1.DataBind();
Session["DataTable"] = dt;
}
}
错误:
“System.NullReferenceException”类型的异常发生在 安全管理 System.dll 但未在用户代码中处理
附加信息:对象引用未设置为 对象。
【问题讨论】:
-
“这个错误”? 什么错误?
-
安全管理 System.dll 中出现“System.NullReferenceException”类型的异常,但未在用户代码中处理其他信息:对象引用未设置为对象的实例。
-
您是否尝试过单步执行代码并找出失败的地方?
标签: html asp.net gridview ado.net