1

我在我的网站上使用jquery ui 可选插件。我在同一页面上有近 7 个带有多选的不同列表,全部使用上述插件。

一旦用户选择了一个特定的列表项......我如何将这些选定的项目传递回代码隐藏?

这就是我在页面上显示我的列表的方式......

<div>
  <ol class="selectable" id="wlList" runat="server" clientidmode="static">
  </ol>
</div>

这就是我在后面的代码中从数据库中生成列表项的方式......

    wl.ToList();
    foreach (var w in wl)
    {
        HtmlGenericControl li = new HtmlGenericControl("li");
        li.Attributes.Add("class", "ui-widget-content");
        li.Attributes.Add("value", w.UserID.ToString());
        li.InnerText = w.FirstName;
        wlList.Controls.Add(li);

    }    

感谢您的帮助

4

1 回答 1

0

一种可能的方法是将选定的值存储在隐藏的输入中,然后在服务器上简单地读取和解析它的值。

检查这个基于jQuery UI Selectable Serialize Demo的小提琴

您需要在表单中添加隐藏输入:

<input type="hidden" id="wlListValue" name="wlListValue" />

然后像这样实现可选的更改处理程序:

$('.selectable').selectable({
    stop: function(event, ui) {
        var result = '';
        $(".ui-selected", this).each(function() {
            result += $(this).val() + ';';
        });
        $('#wlListValue').val(result);
    }
});

然后在回发后读取选定的值:

var selectedValues = Request["wlListValue"].Split(";".ToCharArray(), 
                                    StringSplitOptions.RemoveEmptyEntries);
于 2012-10-04T07:52:46.643 回答