TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shipra Jain
NA
3
981
2 Dropdown lists and a label interdependent
Jul 31 2014 10:36 AM
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
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....
Reply
Answers (
3
)
how to create paging in table in mvc 5
Dynamic Table in MVC 4 Razor