Try Now
More in this section

Forums / Developing with Sitefinity / RadComboBox MultiSelect checkbox

RadComboBox MultiSelect checkbox

2 posts, 0 answered
  1. tim
    tim avatar
    27 posts
    12 Oct 2010
    12 Oct 2010
    Link to this post

    I have a search form with a few comboboxes in it and these contain the item and a checkbox so they can select multiple items. That all works fine and is great but my problem is dealing with saved searches. ie the user comes back and I want to populate the form with their previous choices. I can get it to display a single value using ddl.SelectedValue = "my value"; but obv i need  multiple entries eg: 1, 2, 3, 4 for the ddl.Text value and the checkboxes checked.

    Ive looked around and cant find anything like this but I'm fairly sure I cant be the only one to have this issue. So before I write some hideous javascript (!) I thought I'd check that there isnt a telerik way that I've missed.


    sorted - i think, i'll just use arrays to find the correct checkbox and then mnark it as checked and add the va;lue into the textbox.
  2. tim
    tim avatar
    27 posts
    12 Oct 2010
    13 Oct 2010
    Link to this post
    thought I may as well post the code up here just in case anyone else had the same problem.

    wasn't that bad in the end tbh. Basically from the db I pull my saved values, I know what position in each of the full arrays my saved item is so I can then make new arrays containing the position which is also part of the controls clientID, I dont need to know what the value is just its position in the array and then I can loop through and add them in using a tweaked version of onclick function. I also set the OnClientTabSelected in the RadTabStrip so the results only get populated when the tab is loaded (stops jscript errors). so long as you pump the data in in the correct order should work with any number. (there probably is a nicer way, but this worked for me)

    function setSavedSearch(sender, args)
        //fire it off when we click on the correct tab
        if(args.get_tab().get_text() == "Advanced Search")
            //an array of our comboboxes
            var comboBoxList = ["<%= ddlCaseType.ClientID %>", "<%= ddlCountryList.ClientID %>", "<%= ddlDesignations.ClientID %>"];
            //our generated arrays of saved searchs
            //these are the position in the array the saved value is
            //eg:ddlCaseTypeArray[1] is 3 but represents "Case Type Foo" in my ddlCaseType ComboBox
            var ddlCaseTypeArray = [1, 3, 6, 8, 9];
            var ddlCountryListArray = [2, 5, 6, 8, 9];
            var ddlDesignationsArray = [10, 3, 6, 8, 9];
            //create a 2 dimensional array of our searches
            var ddlControlList = [ddlCaseTypeArray, ddlCountryListArray, ddlDesignationsArray];
            //work through each of our comboboxes from the comboBoxList array
            for(var c = 0; c < comboBoxList.length; c++)
                //find the correct control
                var combo = $find(comboBoxList[c]);
                //clear the text and values
                var text = "";
                var values = "";
                //now we need to loop through our 2D array ddlControlList
                for(var e = 0; e < ddlControlList[c].length; e++)
                    //GET THE CORRECT CHECKBOX
                    var whichOne = $get(combo.get_id() + "_i" + ddlControlList[c][e] +"_chk1");
                    //check it
                    whichOne.checked = true;
                    //get the collection of all items
                    //and do what we normally do when clicking on a checkbox
                    var items = combo.get_items();
                    var item = items.getItem(ddlControlList[c][e]);
                    text += item.get_text() + "," ;
                    values += item.get_value() + ","; 
                //remove the last comma from the string
                text = removeLastComma(text);
                values = removeLastComma(values);
                if (text.length > 0)
                    //set the text of the combobox

2 posts, 0 answered