Here is a routine to select set items and their check/uncheck checkboxes in Javascript.
Hope it helps someone like me who spent some good time trying to figure out why this wasn't as easy as in code behind.
I am sure there are more approaches, but this sub will get you started.
function SetValuesCountryofSales(paramitemstomark) { var witemstomark = paramitemstomark.split("~") var items = _WebDropDown.get_items(); /* Initilized before */ var i = 0; var item = ''; for (i = 0; i <= items.getLength() - 1; i++) { /* Loops through the whole cbo */ item = items.getItem(i); item.unselect(); /* this is if there where selected items */ item.get_element().childNodes[0].checked = false; /* this is if there where selected checked */ for (j = 0; j <= witemstomark.length - 1; j++) { if (item.get_value() == witemstomark[j]) { item.select(); item.get_element().childNodes[0].checked = true; } } } }
Good luck,
Federico.
Hello Federico,
Thank you for sharing your solution with the community!
By the way, in code behind you can use the prerender event, first build the string with a separator this way:
xxxxx~yyyyy~zzzzzz
and do something like this in c.behind:
protected void cboDropDown_PreRender(Object sender, EventArgs e) { string[] witemstomarkList; char[] separator = {'~'}; witemstomarkList = txtstringwithseparators.Text.Split(separator); /*xxxx~yyyy~zzzzzzz */ for (int i = 0; i <= witemstomarkList.Length - 1;i++) { if(witemstomarkList[i].ToString() != ""){ /* I have an item with "" BLANK as no nulls are accepted*/ if (witemstomarkList.Items.FindItemByValue(witemstomarkList[i].ToString()) != null) cboDropDown.Items.FindItemByValue(witemstomarkList[i].ToString()).Selected = true; } } cboDropDown.CurrentValue = txtstringwithseparators.Text; }
Good Luck,
Hope this gets fixed in future releases.