Vuyiswa Maseko ,
Sorry for the confusion , i`m just a little upset about this. Let`s try this aproach:
protected void Page_Load(object sender, EventArgs e)
{
Bind_Combo();
}
private void Bind_Combo()
{
string connStr =
ConfigurationManager.ConnectionStrings["MetrologyConnectionString"].ToString();
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
try
{
cmd.CommandText = "DDLDeviceName";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
string SelectVal = ddlDev.SelectedItem.Text;
if (SelectVal != "")
{
cmd.Parameters.Add("@Name", SqlDbType.NChar, 25).Value = SelectVal;
}
conn.Open();
da.Fill(dt);
ddlDev.Text = "Aparate";
}
catch (SqlException ex)
{
AA.Text = ex.Message;
}
finally
{
if (conn != null)
{
conn = null;
}
}
}
protected void ddlDev_SelectedIndexChanged(object sender, EventArgs e)
{
Session["Var"] = ddlDev.SelectedItem.ToString();
}
Error: Object reference not set to an instance of an object.
Line 42: string SelectVal = ddlDev.SelectedItem.Text;
[NullReferenceException: Object reference not set to an instance of an object.]
All i want is to make the DropDownList to work and on selected item from the DDL to be memorized in a session , we did this so far but the problem is that the DDL is sending only the first value.
And i want to say many thanks for helping me out with this, many many many thanks.
Adrian
Sbadrian, if this helps please login to Mark As Answer. | Alert Moderator