列表框和jQuery [英] listBox And Jquery

查看:79
本文介绍了列表框和jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以任何机构解释我如何能节省上回发两个列表框我用这种我不知道在什么情况下我应该怎么做或者我在哪里可以保存视图状态或如何使用hiddenField的jQuery的状态坚持两个列表框的状态

 < SCRIPT LANGUAGE =JavaScript的类型=文/ JavaScript的>
         $(文件)。就绪(函数(){
            //如果你想选择的项目从fromListBox移动到toListBox
                $(#中)。点击(函数(){
                    $(#+&下;%= fromListBox.ClientID%GT;+选项:选择了)。appendTo(#+&下;%= toListBox.ClientID%GT;');
                });
                //如果要将所有项目从fromListBox移动到toListBox
                $(#的addAll)。点击(函数(){
                    $(#+&下;%= fromListBox.ClientID%GT;+选项)。appendTo(#+&下;%= toListBox.ClientID%GT;');
            });
                //如果你想从toListBox删除所选的项目fromListBox
                $(#删除)。点击(函数(){
                    $(#+&下;%= toListBox.ClientID%GT;+选项:选择了)。appendTo(#+&下;%= fromListBox.ClientID%GT;');
                });
                //如果你想删除toListBox到fromListBox所有项目
                $(#的removeAll)。点击(函数(){
                    $(#+&下;%= toListBox.ClientID%GT;+选项)。appendTo(#+&下;%= fromListBox.ClientID%GT;');
                });            });
                  < / SCRIPT>< ASP:列表框ID =fromListBox=服务器的SelectionMode =多HEIGHT =150像素WIDTH =150像素>< ASP:ListItem的文本=招生IDVALUE =enrollment_no>< / ASP:ListItem的> < ASP:ListItem的文本=学生姓名VALUE =FIRST_NAME>< / ASP:ListItem的> < ASP:ListItem的文本=姓VALUE =姓氏>< / ASP:ListItem的> < ASP:ListItem的文本=父亲姓名VALUE =father_name>< / ASP:ListItem的>< / ASP:列表框>< ASP:列表框=服务器ID =toListBox>< / ASP:列表框>


解决方案

我觉得你刚才应该使用普通的HTML列表框,而不是asp.net服务器控件。
<一href=\"http://stackoverflow.com/questions/212988/listbox-elements-rearranged-with-javascript-causing-event-validation-error-on-pos\">Here关于它的一些技巧。和这里你可以找到体面的code jQuery的,将移动项目beetween列表框。

我觉得你有三种选择:


  • 使用普通的HTML列表框,写一些javascript code,并采用标准的POST请求在服务器上与他们操作。

  • 使用的UpdatePanel与你的列表框(你会消除页面闪烁,你可能不会有使用jQuery或重写现有的code)

  • 找到或编写自己的控件,使用JavaScript来移动项目和管理视图状态本身

我会使用HTML列表框(选择元素),以避免视图状态的问题。它会为您节省大量的时间。

could any body explain me how can i save state of two list boxes on post back i am using jQuery of this kind i dont know on what event what should i do or where can i save view state or how can i use hiddenField to persist the state of both list box

<script language="javascript" type="text/javascript">
         $(document).ready(function() {
            //If you want to move selected item from fromListBox to toListBox
                $("#add").click(function() {
                    $("#"+'<%= fromListBox.ClientID %>'+" option:selected").appendTo("#"+'<%=toListBox.ClientID %>');
                });
                //If you want to move all item from fromListBox to toListBox
                $("#addAll").click(function() {
                    $("#"+'<%= fromListBox.ClientID %>'+" option").appendTo("#"+'<%=toListBox.ClientID %>');
            });
                //If you want to remove selected item from toListBox to fromListBox
                $("#remove").click(function() {
                    $("#"+'<%=toListBox.ClientID %>'+" option:selected").appendTo("#"+'<%= fromListBox.ClientID %>');
                });
                //If you want to remove all items from toListBox to fromListBox
                $("#removeAll").click(function() {
                    $("#"+'<%=toListBox.ClientID %>'+" option").appendTo("#"+'<%= fromListBox.ClientID %>');
                });

            });
                  </script>

<asp:ListBox ID="fromListBox" runat="server" SelectionMode="Multiple" Height="150px" Width="150px"  >

<asp:ListItem Text="Student Enrollment ID" Value="enrollment_no"></asp:ListItem> <asp:ListItem Text="Student Name" Value="first_name"></asp:ListItem> <asp:ListItem Text="Last Name" Value="last_name"></asp:ListItem> <asp:ListItem Text="Father Name" Value="father_name"></asp:ListItem>

</asp:Listbox>

<asp:ListBox runat="server" ID="toListBox" ></asp:ListBox>

解决方案

I think you just should use normal html listboxes, not asp.net server controls. Here are some tips about it. And here you can find decent code for jquery that will move items beetween listboxes.

I think you have three options:

  • Use normal HTML listboxes, write some javascript code, and manipulate with them on server using standard POST request.
  • Use UpdatePanel with your listboxes (you'll eliminate page flickering and you probably wont have to use jQuery or rewrite your existing code)
  • Find or write your own control that uses javascript to move items and manage viewstate itself

I would use HTML listboxes (select elements) to avoid viewstate issues. It'll save you a lot of time.

这篇关于列表框和jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆