Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
135
WebDropDown - Clear Old selected values
posted

My problem:

I have two webdropdown's used in a cascading fashion with multiple selection.

When the user selects a record from the 1st dropdown, the second dropdown is loaded with the corresponding values. That part is fine.

The real problem comes into play when I check the checkboxes and then I goto the 1st dropdown and reselect another item. The old values are still there. I need them to clear.

I've looked at other post and found similar problems, but nothing the same. (Setting the CurrentValue = "", etc.)

Example: Lets say the 1st dropdown is called "Locations" and the 2nd is called "Location Problems"

I select in the 1st dropdown the value of "Florida". In the 2nd dropdown, all the problems in florida are listed. I check 2 problems from the list ("Heat","Rain"). I change my mind and I want to select "Georgia" from the first dropdown, but the old "Problems" are still there ("Heat","Rain"). I need them to clear.

Not all "States" have "Problems" also. So, when selecting "Georgia" nothing should appear and I then want to DISABLE the 2nd dropdown b/c there are no values.

 

Putting it in a AJAX.NET update panel did not work. Here is the code below:

    <script type="text/javascript">
        function ContractChanging(sender, eventArgs) {
            var combo2 = $find('<%= ddlWritingCompany.ClientID %>');
            combo2.loadItems(eventArgs.getNewSelection()[0].get_value());
        }
</script>

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
   
        <ig:WebDropDown ID="ddlContract" runat="server" Width="500px"
            CurrentValue=""
            ValueField="ID"
            TextField="CONTRACT_FORMATTED_NAME"
            DataSourceID="sqldsContracts"
            EnableAutoCompleteFirstMatch="false"
            DropDownContainerHeight="250px"
            EnableLoadOnDemand="true"
            EnableAutoFiltering="Server"
            EnableViewState="False" LoadingItemsMessageText="Loading...">
            <ClientEvents SelectionChanged="ContractChanging" />
        </ig:WebDropDown>
   
        <asp:SqlDataSource ID="sqldsContracts" runat="server" ConnectionString="<%$ ConnectionStrings:CarrierDBConnectionString %>"
            SelectCommand="APPOINTMENT_CONTRACT_SELECT_ALL"
            SelectCommandType="StoredProcedure" />
        <br />
   
        <ig:WebDropDown ID="ddlWritingCompany" runat="server" Width="500px"
            EnableDropDownAsChild="false"
            EnableAutoCompleteFirstMatch="false"
            EnableMultipleSelection="true"
            EnableClosingDropDownOnSelect="false"
            LoadingItemsMessageText="Loading..."
            MultipleSelectionType="Checkbox"
            TextField="Text" ValueField="Value"
            CurrentValue="">
        </ig:WebDropDown>

 

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        ddlWritingCompany.ItemsRequested += new DropDownItemsRequestedEventHandler(ddlWritingCompany_ItemsRequested);
    }

    protected void ddlWritingCompany_ItemsRequested(object sender, Infragistics.Web.UI.ListControls.DropDownItemsRequestedEventArgs e)
    {
        string value = (string)e.Value;

        WebDropDownDataCommand wddc = new WebDropDownDataCommand();
        IList<WebDropDownItem> list = wddc.GetData(Convert.ToInt32(value));

        if (list.Count != 0)
        {
            ddlWritingCompany.DataSource = list;
        }
        else
        {
            ddlWritingCompany.CurrentValue = "";
        }
    }

 

Pleas help. Spent to much time and effort on this crap already.

Thanks

Parents
No Data
Reply
  • 24671
    Suggested Answer
    posted

    Hi,

    You don't need to reset innerHTML on any element. This is automatically handled by the loadItems call. 

    If i understand your scenario correctly, your input value of the second dropDown is not updated correctly. This probably happens because the loadItems only reloads the data , but doesn't update the input (i.e. currentValue is there, but visually it doesn't get updated). You could use the ItemsRequested event for the second dropdown, when items are already there on the client-side, and set it like this:

         function itemsRequested(sender, args) {

     

                sender.set_currentValue(sender.get_items().getItem(0).get_text(), true);

            }

    and then in the control markup:

     <ClientEvents ItemsRequested="itemsRequested" />

     

    In order to disable the dropdown , you can use the set_enabled(false) client-side function on the control. It will do all the necessary actions to make the controls disabled (set input box as disabled and make sure dropdown cannot be opened by the users). In order to decide whether you have to disable it or not, you can either get the number of items and compare to zero, or get the currentValue property and compare to empty string.

    var dropDown2ChoicesCount = dropDown2.get_items().getLength(); 

    (you can do this in the itemsRequested event handler as well). 

    Hope it helps,

    Angel 

Children
No Data