Creating Dependent DropDownLists...
Forcing the contents of one DropDownList to change based upon the selection of a value from another DropDownList.
How can do so in C#(Asp.net)
i have kept a dropdownlsits for locations --->
Droploc1 ---of locations
and acording to this i have to bind datas to my second dropdwnlsts
Droplab--which contains labs according to a particular locations
Hope u all have understood this,i will give my code here but its not working!!!
Droplab.Items.Clear();
SqlConnection cone1 = new SqlConnection(@"Server=sqloledb.1;User ID=sa;password=;Data Source=IRID_BDC1;Initial Catalog=hello");
string searchVal1=Droploc1.SelectedItem.Text;
Labwelc.Text=searchVal1;
string selectSQL1 = "SELECT Lab from Loc_det where Lab='"+searchVal1+"'";
//string searchVal1=Droploc1.SelectedItem.Text;
//Response.Write(Droploc1.SelectedItem.Text);
SqlCommand cmdd = new SqlCommand(selectSQL1, cone1);
SqlDataReader reader1;
try
{
cone1.Open();
reader1 = cmdd.ExecuteReader();
while(reader1.Read())
{
ListItem newItem = new ListItem();
newItem.Text = reader1["Lab"].ToString();
//newItem.Value = reader1["Slno"].ToString();
Droplab.Items.Add(newItem);
}
reader1.Close();
}
catch (Exception err)
{
Labwelc.Text = "Error reading list of lab. ";
Labwelc.Text += err.Message;
}
finally
{
cone1.Close();
}