嗨,我想在我的窗體中使用jQuery UI的拖放功能。我綁定數據庫中的第一個lisbox項目。我想要的是將項目從list1拖到list2。我嘗試了下面的代碼來實現它,這是我無法實現的。請幫我解決這個問題。在asp.net中將項目從一個列表框拖放到另一個列表框中
<script type="text/javascript">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
$(function() {
$("#list1, #list2").sortable({
connectWith: ".connectedSortable"
}).disableSelection();
});
</script>
<style>
#list1, #list2 {
border: 1px solid #eee;
width: 142px;
min-height: 20px;
list-style-type: none;
margin: 0;
padding: 5px 0 0 0;
float: left;
margin-right: 10px;
}
#list1li, #list2 li {
margin: 0 5px 5px 5px;
padding: 5px;
font-size: 1.2em;
width: 120px;
}
<asp:ListBox ID="list1" runat="server" Height="300px" Width="250px" class="connectedSortable"></asp:ListBox>
<asp:ListBox ID="list2" runat="server" Height="300px" Width="250px" class="connectedSortable"></asp:ListBox>
後面的代碼綁定列表1 ListBox控件
public void BindListbox()
{
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "[get_names]";
cmd.Connection = con;
try
{
con.Open();
list1.DataSource = cmd.ExecuteReader();
list1.DataTextField = "Antibiotic";
list1.DataValueField = "AntibioticId";
list1.DataBind();
}
catch (Exception ex)
{
Response.Write("Error occured: " + ex.Message.ToString());
}
finally
{
con.Close();
con.Dispose();
}
}