0

JQuery UI Multiselect プラグインを使用して、複数選択項目でドロップダウン リストを使用しています。データベースに保存されている選択項目を複数選択ドロップダウンに戻すには助けが必要です。

例:

ページ読み込み時の Javascript コード:

$("#<%=ddlCountry.ClientID%>").multiselect({
            checkAllText: "All",
            uncheckAllText: "Clear",
        noneSelectedText: "Select a country",
        selectedText: "# item(s) selected",
        close: function (event, ui) {
            var values = $("#<%=ddlCountry.ClientID%>").val();
            var array_of_checked_values = $("#<%=ddlCountry.ClientID%>").multiselect("getChecked").map(function () {
                return this.value;
            }).get();
            document.getElementById("<%=txtHidDataCountry.ClientID%>").value = array_of_checked_values;
        }
    });

DropDownList ASPX コード:

<div id="dvPais" style="display:none">
   <asp:DropDownList ID="ddlCountry" runat="server">
    </asp:DropDownList>
    <input type="hidden" id="txtHidDataCountry" runat="server" />
</div>

3 つの国を選択して送信を完了すると、「1,2,3」のような値になります。ページを再度読み込むときに、ドロップダウンリストから項目 1、2、3 を選択する必要があります。どうやってやるの?

4

1 に答える 1

1

私が見つけた解決策を与えるだけです:

$("#<%=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 コード:

<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>

楽しみ :)

于 2012-10-11T18:13:28.033 に答える