Jquery UI Multiselect bind items from codebehind

you can use :

$("#<%=ddlTeste.ClientID%>").multiselect({
        checkAllText: "All",
        uncheckAllText: "Clear",
    noneSelectedText: "Select a country",
    selectedText: "# item(s) selected",
    close: function (event, ui) {
        var values = $("#<%=ddlTeste.ClientID%>").val();
        var array_of_checked_values = $("#<%=ddlTeste.ClientID%>").multiselect("getChecked").map(function () {
            return this.value;
        }).get();
        document.getElementById("<%=txtHidDataTeste.ClientID%>").value = array_of_checked_values;
    }
});
var s = $("#<%=ddlTeste.ClientID%>").multiselect();
s.val(['1', '2','5']);
$("#<%=ddlTeste.ClientID%>").multiselect('refresh');
ASPX code:
<asp:DropDownList ID="ddlTeste" runat="server" multiple>
    <asp:ListItem Value="1">Valor 1</asp:ListItem>
    <asp:ListItem Value="2">Valor 2</asp:ListItem>
    <asp:ListItem Value="3">Valor 3</asp:ListItem>
    <asp:ListItem Value="4">Valor 4</asp:ListItem>
    <asp:ListItem Value="5">Valor 5</asp:ListItem>
</asp:DropDownList>

Comments

Popular posts from this blog

C# Crop white space from around the image

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

The specified version string contains wildcards, which are not compatible with determinism.