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?
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
ClearSelection() is not a method within the WebDropDown. Using unselect() client-side does not solve my issue either. I am not using CheckBoxes, all I want to do is to be able to return the WebDropDown to it's Initial State client-side. I.e. when the user first goes to the page it says "Please wait..". I then want to be able to reset it after a user has selected an item in the list. I.e. similar to the way you can call ComboBox.SelectedIndex = -1; on a standard MS Control.