Posted on: 6/17/2014 7:51:48 PM | Views : 278

I have a DropDownList and ListBox in my webpage,
the dropdownlist has a list from a table(companies). When I select a company, then the ListBox will list all departments in that selected company.
my code:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) {
string name = DropDownList1.SelectedItem.ToString(); string sql = "Select [Dept] from Company where [CompanyName] = '" + name + "'"; DataTable dt = getTable(sql); foreach (DataRow dr in dt.Rows) { ListBox1.Items.Add(dr["Dept"].ToString()); } ListBox1.Items.Insert(0, "All"); ListBox1.Items[0].Value = "All";
}
does not work when select from ddl unless I have a control (like button click).
What did I miss?
Thanks.

Go to the complete details ...