2011-05-04 77 views

回答

2

有很多網絡上可用的插件,但你可以通過使用Java script.I實現創建了一個示例應用程序在asp.net.Check出來,讓我知道你是否有任何疑問。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ST.aspx.cs" Inherits="ST" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <script language="javascript" type="text/javascript"> 
     var d; 
     function drag(objSource) { 
      this.select = objSource; 
     } 

     function drag.prototype.drop(objDest) { 
      if (!this.dragStart) return; 
      this.dest = objDest; 

      var o = this.option.cloneNode(true); 
      this.dest.appendChild(o); 
      this.select.removeChild(this.option); 
     } 

     function drag.prototype.setIndex() { 
      var i = this.select.selectedIndex; 

      //i returns -1 if no option is "truly" selected 
      window.status = "selectedIndex = " + i; 
      if (i == -1) return; 

      this.option = this.select.options[i]; 
      this.dragStart = true; 
     } 

    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:ListBox ID="one" runat="server" onmousedown="d = new drag(this);" onmouseup="d.drop(this.form.two);" 
      onmouseout="if (typeof d != 'undefined') d.setIndex();"> 
      <asp:ListItem Text="Opt1" Value="1"></asp:ListItem> 
      <asp:ListItem Text="Opt2" Value="2"></asp:ListItem> 
      <asp:ListItem Text="Opt3" Value="3"></asp:ListItem> 
     </asp:ListBox> 
     <asp:ListBox ID="two" runat="server"> 
      <asp:ListItem Text="Opt1" Value="1"></asp:ListItem> 
      <asp:ListItem Text="Opt2" Value="2"></asp:ListItem> 
      <asp:ListItem Text="Opt3" Value="3"></asp:ListItem> 
     </asp:ListBox> 
    </div> 
    </form> 
</body> 
</html> 
+0

我無法得到這個例子的工作。我在.net 4.0上。 – MikeTeeVee 2011-12-12 19:43:20

0

這就是我實現它的方式。數據來自數據庫,我使用listview來顯示列表。

<table> 
    <tr> 
     <td> 
      <asp:ListView ID="Listview1" runat="server" DataSourceID="LinqDataSource1" > 
       <LayoutTemplate> 
        Unallocated Sections 
        <asp:Label ID="Setter Count" runat="server"></asp:Label> 
    <ul class="sortable" draggable="true" id="Setter" style="overflow: scroll; empty-cells: hide; height: 500px; width: 200px; border: solid 1px; background: #b6b6b6;" > 
     <li id="Li1" runat="server" draggable="true" style="user-select: element;" > 
      <asp:PlaceHolder ID="PlaceHolder1" id-="itemPlaceholder" runat="server" ></asp:PlaceHolder> 
     </li> 

    </ul> 
       </LayoutTemplate> 
       <ItemTemplate> 
        <li id="Li2" runat="server" title="Drag to Allocate sections" > 
         <%# Eval("Section")%> 
        </li> 
       </ItemTemplate> 
      </asp:ListView> 
     </td> 
     <td>Allocated Sections 
      <asp:Label ID="GetterCount" runat ="server"></asp:Label> 
      <ul class="sortable" draggable="true" id="Getter" style="overflow: scroll; height: 500px; width: 200px; border: solid 1px; background: #fff;"> 
       <li style="color: red;"></li> 
      </ul> 
     </td> 
    </tr> 
</table> 

jQuery的使用情況如下:

<script> 

    $(function() { 
     $("#Setter,#Getter").sortable({ 
      connectWith: ".sortable" 
     }).selectable(); 
    }); 

</script> 

我希望這有助於。欲瞭解更多選項,你可以檢查jQuery UI: Sortable