{
DropDownList2.Items.Clear();
string spec = DropDownList1.SelectedValue.ToString();
con.Open();
string qry = "select Name,Timing from Team where Speciality=@spec";
SqlCommand cmd = new SqlCommand(qry, con);
cmd.Parameters.AddWithValue("@spec", spec);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
DropDownList2.Items.Add(dr[0].ToString());
}
}
con.Close();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
//string doc = DropDownList2.SelectedValue.ToString();
con.Open();
string qry2 = "select Timing from Team where Name='"+ DropDownList2.SelectedValue.ToString() +"'";
SqlCommand cmd1 = new SqlCommand(qry2, con);
//cmd1.Parameters.AddWithValue("@doc", doc);
SqlDataReader dr1 = cmd1.ExecuteReader();
if (dr1.HasRows)
{
Label8.Text = dr1[0].ToString();
}
con.Close();
}
What I am trying to do is:
There are 2 dropdown lists. The values in 2nd gets changed based on the value selected in 1st list.
Now, I need to display the timings(in database) for the value now selected in dropdownlist 2.
But I am getting incorrect values...
Kindly respond me with the way to correct it asap....
Guest UserRank #258 · 9.8K pointsPosted Aug 1, 2014, 6:03 PM EDT
why are you writing code in dropdown2 to save data into db, you can do this in dropdown 1 itself or at click of any button
Shipra Jain2 pointsPosted Aug 2, 2014, 10:54 PM EDT
Guest UserRank #258 · 9.8K pointsPosted Aug 3, 2014, 4:20 PM EDT
twitter @sumitjolly