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
595
WebDropDown - Cannot clear selected item Client-Side
posted

I've got the following code for clearing the selections and resetting the WebDropDown server side:


            foreach (Infragistics.Web.UI.ListControls.DropDownItem item in WebDropDown1.Items)
            {
                if (item.Selected)
                {
                    item.Selected = false;
                }
            }

            this.WebDropDown1.CurrentValue = "Please select...";

This works, although is very complex considering there should be an easy way to do this... i.e. WebDropDown1.SelectedIndex = -1 like a normal WinForm control. Even WebDropDown1.SelectedItems.Clear() would be better.

I'm now trying to do the same thing Client-Side. This is the code I have that doesn't work:

        function Reset()
        {    
            var dropDown = $find('<%=WebDropDown1.ClientID %>');
            var selectedList = dropDown.get_selectedItems();
            for (var i = 0; i< selectedList.length; i++)
            {
                selectedList[i].set_selected(false);
            }
            dropDown.set_currentValue("Please select...", false);
        }

How can this be done client-side?

Parents
  • 24671
    posted

    Hi,

    On the server you canjust call WebDropDown1.ClearSelection()  - that should be working fine with the latest service release. This method was present before but was not part of the public API.

    As for the client-side, it's probably working fine , I suppose the issue is that you are not visually seeing any difference in terms of selected vs. not selected item. That's because set_selected only updates the item's state, but not its CSS class. If you want the CSS and everything (visually) to update as well, you can use the select() function on the item:

    selectedList[i].select() or selectedList[i].unselect() 

    That should do it. In case you have multiple checkbox selection, it will also automatically check / uncheck the item's checkbox.

    Hope it helps, and thanks for your feedback,

    Angel 

Reply Children