This is page load where I make two columns in data table and also connect database with dropdown-list:
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();
}
Code side this is a temporary data grid:
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;
}
}
Error:
An exception of type 'System.NullReferenceException' occurred in Security Managment System.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.