I have multiple WebDropDown controls in an ASP:Formview on my page. The business logic "wires" them together, and they are dependent on each other. I have various client and server-side events that handle most of the business logic, but I have run into one specific scenario that isn't working. I'm not sure if it's because the order of events that are firing, or if I'm missing a javascript function, etc. The business logic requires this:For example, my page looks like this:----------------------------------------------------------------------------------------------------------------------------------------Select Primary Category: [WebDropdown 1]Select Primary Product: [WebDropdown 2]Select Secondary Category 1: [WebDropdown 3] Select Secondary Product 1: [WebDropdown 4]Select Secondary Category 2: [WebDropdown 5] Select Secondary Product 2: [WebDropdown 6]Select Secondary Category 3: [WebDropdown 7] Select Secondary Product 3: [WebDropdown 8]Select Secondary Category 4: [WebDropdown 9] Select Secondary Product 4: [WebDropdown 10]Select Secondary Category 5: [WebDropdown 11] Select Secondary Product 5: [WebDropdown 12]----------------------------------------------------------------------------------------------------------------------------------------The source of information is the same for the Category fields, and the source of information for the Product fields is the same. These are the business rules:Rule#1All Categories must be unique. There cannot be duplicate values in the Category fields. On page load, if Primary Category = 'Shoes' is selected, then the Secondary Categories cannot also have 'Shoes'. (The value 'Shoes' must not exist in the drop-down list in the Secondary Categories). Rule#2If the user picks a Secondary Category 1 = "Hats", then "Hats" cannot exist in the Secondary Category 2-5 drop down lists. Rule#3All Categories must be unique. There cannot be duplicate values in the Category fields. After a Primary Category is selected, there are two things that need to happen: 1.) the associated products display in the Primary Product drop-down (cascading), and 2.) the selected Primary Category must be removed from the Secondary Category 2-5 drop down lists (enforcing uniqueness - not displaying them as a selection). Rule#4 After a Secondary Category is selected, the associated products display in the corresponding Secondary Product drop-down. For example, if Secondary Category 1 = 'Shoes', then all shoe products must display in the Secondary Product 1 drop down list.Rules 1, 2, and 4 are currently working. My problem is that Rule 3 item#2 is not working. This is what the markup looks like for the WebDropdown controls on the page:
<ig:WebDropDown ID="ddlPrimaryCategory" runat="server" AutoPostBack="false" EnablePaging="false" PageSize="10" EnableRenderingAnchors="false" ForeColor="Black" DataSourceID="ddlPrimaryCategorySqlDataSource" Visible="true" Width="350" selectedValue='<%# Bind("category_code") %>' OnPreRender="ddlPrimaryCategory_OnPreRender" OnDataBound="ddlPrimaryCategory_OnDataBound" OnSelectionChanged="ddlPrimaryCategory_OnSelectionChanged" DisplayMode="DropDown" KeepFocusOnSelection="true" > <ClientEvents DropDownClosed="ddlPrimaryCategoryDropDownClosed" /> <DropDownItemBinding TextField="category_desc" ValueField="category_code" /></ig:WebDropDown> <asp:SqlDataSource ID="ddlPrimaryCategorySqlDataSource" runat="server"ConnectionString="<%$ ConnectionStrings:PDMConnectionString %>"OnDataBinding="ddlPrimaryCategorySqlDataSource_OnDataBinding"SelectCommandType="StoredProcedure"SelectCommand="SELECT_MASTER_CATEGORY_LIST" ></asp:SqlDataSource>
<ig:WebDropDown ID="ddlPrimaryProduct" runat="server" EnablePaging="false" PageSize="10" DataSourceID="ddlPrimaryProductSqlDataSource" Width="350" OnItemsRequested="ddlPrimaryProduct_OnItemsRequested" OnDataBound="ddlPrimaryProduct_OnDataBound" selectedValue='<%#DataBinder.Eval(Container.DataItem,"product_code") %>' OnPreRender="ddlPrimaryProduct_PreRender" OnSelectionChanged="ddlPrimaryProduct_OnSelectionChanged" EnableRenderingAnchors="false" ForeColor="Black" > <DropDownItemBinding TextField="product_desc" ValueField="product_code" /></ig:WebDropDown><asp:SqlDataSource ID="ddlPrimaryProductSqlDataSource" runat="server"ConnectionString="<%$ ConnectionStrings:PDMConnectionString %>"OnDataBinding="ddlPrimaryProductSqlDataSource_OnDataBinding"SelectCommandType="StoredProcedure"SelectCommand="SELECT_MASTER_PRODUCT_LIST" ></asp:SqlDataSource
<ig:WebDropDown ID="ddlSecondaryCategory1" runat="server" Width="350px" AutoPostBack="false" selectedValue='<%# DataBinder.Eval(Container.DataItem,"secondary_category1")%>' OnItemsRequested="ddlSecondaryCategory1_OnItemsRequested" OnPreRender="ddlSecondaryCategory1_OnPreRender" OnDataBound="ddlSecondaryCategory1_OnDataBound" Visible="true" EnablePaging="false" PageSize="10" EnableRenderingAnchors="false" ForeColor="Black" > <DropDownItemBinding TextField="category_desc" ValueField="category_code" /> <ClientEvents SelectionChanged="ddlSecondaryCategory1SelectionChanged" /> </ig:WebDropDown><ig:WebDropDown ID="ddlSecondaryProduct1" runat="server" Width="350px" Visible="true" AutoPostBack="false" OnPreRender="ddlSecondaryProduct1_OnPreRender" OnDataBound="ddlSecondaryProduct1_OnDataBound" OnItemsRequested="ddlSecondaryProduct1_OnItemsRequested" EnablePaging="false" PageSize="10" EnableRenderingAnchors="false" ForeColor="Black" selectedValue='<%# DataBinder.Eval(Container.DataItem,"secondary_product1") %>' > <DropDownItemBinding TextField="product_desc" ValueField="product_code" /></ig:WebDropDown>The markup for the other Secondary Category 2-5 and Secondary Product 2-5 webdropdown controls is the same as above. The Javascript functions that are called in the <ClientEvents> are:function ddlPrimaryCategoryDropDownClosed (sender, e) { var ddlPrimaryProduct = $find(ddlPrimaryProduct_id); //get value selected in primary practice var newSelection = sender.get_selectedItem().get_value(); //stuff it into hidden field var hdnPPval = document.getElementById(hdnPPval_id); hdnPPval.value = newSelection; //show corresponding products in Primary Product drop down list ddlPrimaryProduct.loadItems(newSelection);}This is in the code-behind:protected void ddlPrimaryProduct_OnSelectionChanged (object sender, EventArgs e) {Infragistics.Web.UI.ListControls.WebDropDown ddlPrimaryCategory =(Infragistics.Web.UI.ListControls.WebDropDown)sender; //Remove newly selected primary category from secondary categories 1-5removeSelectedPrimaryCategoryFromSecondaryCategories(ddlPrimaryCategory.SelectedValue); }This is the removeSelectedPrimaryCategoryFromSecondaryCategories method:protected void removeSelectedPrimaryCategoryFromSecondaryCategories(string selectedPrimaryCategory) {string selectedSecondaryProduct1_value = "";string selectedSecondaryProduct2_value = "";string selectedSecondaryProduct3_value = "";string selectedSecondaryProduct4_value = "";string selectedSecondaryProduct5_value = "";Infragistics.Web.UI.ListControls.WebDropDown ddlSecondaryCategory1 = (Infragistics.Web.UI.ListControls.WebDropDown)FormView1.FindControl("ddlSecondaryCategory1");Infragistics.Web.UI.ListControls.WebDropDown ddlSecondaryCategory2 =(Infragistics.Web.UI.ListControls.WebDropDown)FormView1.FindControl("ddlSecondaryCategory2");
Infragistics.Web.UI.ListControls.WebDropDown ddlSecondaryCategory3 = (Infragistics.Web.UI.ListControls.WebDropDown)FormView1.FindControl("ddlSecondaryCategory3");Infragistics.Web.UI.ListControls.WebDropDown ddlSecondaryCategory4 = (Infragistics.Web.UI.ListControls.WebDropDown)FormView1.FindControl("ddlSecondaryCategory4");Infragistics.Web.UI.ListControls.WebDropDown ddlSecondaryCategory5 = (Infragistics.Web.UI.ListControls.WebDropDown)FormView1.FindControl("ddlSecondaryCategory5");selectedSecondaryProduct1_value = ddlSecondaryCategory1.SelectedValue;selectedSecondaryProduct2_value =ddlSecondaryCategory2.SelectedValue;selectedSecondaryProduct3_value =ddlSecondaryCategory3.SelectedValue;selectedSecondaryProduct4_value =ddlSecondaryCategory4.SelectedValue;selectedSecondaryProduct5_value =ddlSecondaryCategory5.SelectedValue;//Populate Secondary Category 1 drop down - exclude other Secondary Category pre-selected values (if they exist)ddlSecondaryCategory1.Items.Clear();DataTable dt = new DataTable();dt = mBLL.spBuild_SecondaryCategory1_DDList(selectedPrimaryCategory, selectedSecondaryCategory2_value,selectedSecondaryCategory3_value,selectedSecondaryCategory4_value,selectedSecondaryCategory5_value);ddlSecondaryCategory1.DataSource = dt;ddlSecondaryCategory1.DataBind();//Populate Secondary Category 2 drop down - - exclude other Secondary Category pre-selected values (if they exist)ddlSecondaryCategory2.Items.Clear();dt = mBLL.spBuild_SecondaryCategory2(selectedPrimaryCategory,selectedSecondaryCategory1_value,selectedSecondaryCategory3_value,selectedSecondaryCategory4_value,selectedSecondaryCategory5_value);ddlSecondaryCategory2.DataSource = dt;ddlSecondaryCategory2.DataBind();....The code for the Secondary Category 3-5 drop down lists is similar.}Problem is...The page does not display the updated Secondary Category drop down lists.Is there something else that needs to happen in order for the updated Secondary Category lists to display on the page (refresh)?Thank you,
Chris
Hi Chris,
Thank you for posting in the community.
I am attaching a sample illustrating how your requirement of removing items on "secondary" dropdowns in order to enforce uniqueness may be achieved. For the sake of simplicity and clarity my sample uses just two dropdowns. Below is the code used for the SelectionChanged handling:
Please let me know if this helps.
I added this code to my "OnSelectionChanged" property for my WebDropDown1 (which is in a Formview):<ig:WebDropDown ID="WebDropDown1" runat="server" Width="350px" AutoPostBack="false" selectedValue='<%# DataBinder.Eval(Container.DataItem,"secondary_practice1")%> OnItemsRequested="WebDropDown1_OnItemsRequested" OnPreRender="WebDropDown1_OnPreRender" OnDataBound="WebDropDown1_OnDataBound" OnSelectionChanged="WebDropDown1_OnSelectionChanged" Visible="true" EnablePaging="false" PageSize="10" EnableRenderingAnchors="false" ForeColor="Black"> <DropDownItemBinding TextField="dept_desc" ValueField="dept_code" /></ig:WebDropDown>I noticed that the 'selectedItemValue' is the number which represents where the selected value is in the list. For example, if the user picked the first value in the list, selectedItemValue = 1. If the user picked the second value in the list, selectedItemValue = 2. I modified the code to give the selected value like this:protected void ddlSCP1_OnSelectionChanged(object sender, Infragistics.Web.UI.ListControls.DropDownSelectionChangedEventArgs e){ Infragistics.Web.UI.ListControls.WebDropDown ddlSCP2 = (Infragistics.Web.UI.ListControls.WebDropDown)FormView1.FindControl("ddlSCP2"); Infragistics.Web.UI.ListControls.WebDropDown ddlSCP1 = (Infragistics.Web.UI.ListControls.WebDropDown)sender; //string selectedItemValue = e.NewSelection.ToString(); string selectedItemValue = ddlSCP1.SelectedValue; if (ddlSCP2.Items.FindItemByValue(selectedItemValue) != null) { ddlSCP2.Items.Remove(ddlSCP2.Items.FindItemByValue(selectedItemValue)); }}This removed the selected value. Just curious, is there something else that I'm missing why "e.NewSelection.ToString(); " didn't work for me?Thank you,Chris