Hi I've a dropdown list with datasource like
empname dept
-----------------
Rahul 02
martin 01
sachin 02
i've binded this table to my dropdown list and when i try to access dept in dropdown selected event change every time I'm getting Rahul only. even i selected sachin.
Whats the problem? What I assume is I've two common values in my datavalue field (02 and 02) is this a problem?
Please check my code shown below..
if (!IsPostBack)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand("toget_emp", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
ddlReason.DataSource = ds.Tables[0];
ddlReason.DataTextField = "empname";
ddlReason.DataValueField = "dept";
ddlReason.DataBind();
ddlReason.Items.Insert(0, "--Select--");
}
}
catch (SqlException ex)
{
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "javascript:alert('" + ex.Message + "')", true);
}
finally
{
con.Close();
}
}