Hi Everyone,
I was wondering if someone can help me. I have 3 DropDown menus, lets say Menu A, Menu B, and Menu C. When I make a selection in Menu A, It fills Menu B with data. And, when I make a selection with Menu B, it fills Menu C with data. But My problem is, when I try to select something in Menu B, the OnSelectionChanged for Menu A also fires on the postback when the OnSelectionChanged for Menu B should be the only one firing and I can't figure out why. Any suggestions? I hope I explained this clearly. Thanks in advance!
Jay
JayPosted Apr 14, 2009, 8:44 AM
Hi,
Here is some sample code.....
This code populates the ddCats dropdown when an option is selected in ddDepts
protected void ddDepts_SelectedIndexChanged(object sender, EventArgs e){
string mainDepartment = Request.QueryString["Department"]; string deptID = ddDepts.SelectedValue; string catID, catName;ddSubCats.Items.Clear();
if (mainDepartment == "ThisDepartment"){
DataTable table = CatalogAccess.GetCategoriesInDepartment(deptID); for (int i = 0; i < table.Rows.Count; i++){
catID = table.Rows[i][
"CategoryID"].ToString();catName = table.Rows[i][
"Name"].ToString();ddCats.Items.Add(
new ListItem(catName, catID));}
}
}
This code populates ddSubCats dropdown when an option is selected in ddCats
protected void ddCats_SelectedIndexChanged(object sender, EventArgs e){
string mainDept = Request.QueryString["Department"]; string productID = Request.QueryString["ProductID"]; string deptID = ddDepts.SelectedValue; string catID = ddCats.SelectedValue; string catName = ddCats.SelectedItem.ToString(); string subCatID, subCatName;lblSubCats.Text =
"";ddSubCats.Items.Clear();
DataTable table; if (mainDept == "ThisDepartment"){
table =
CatalogAccess.GetSubCategoriesInCategories(catID, deptID); for (int i = 0; i < table.Rows.Count; i++){
subCatID = table.Rows[i][
"SubCategoryID"].ToString();subCatName = table.Rows[i][
"Name"].ToString();ddSubCats.Items.Add(
new ListItem(subCatName, subCatID));}
}}
Now the main problem I have is when I make a selection in ddCats, firing the ddCats_SelectedIndexChanged, the ddDepts_SelectedIndexChanged also fires, there for not not populating the ddSubCats correctly because the ddCats "resets". Is there a way when I select something from ddCats, the ddDepts_SelectedIndexChanged doesn't fire?
Thanks
Jay
Jan MontanoPosted Apr 13, 2009, 8:11 PM