I have the drag-and-drop working.
if you try to drag-and-drop a duplicate and get the error message, the drag-and-drop process stops working.
So is there any way to prevent duplicates and do a copy instead of move without cancelling the sortable plugin?
Here is my code:
<%@ Page Title="" Language="C#" MasterPageFile="~/EconomicInterest.Master" AutoEventWireup="true" CodeBehind="Testing.aspx.cs" Inherits="EconomicInterestWebApp.Testing" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<link href="../css/PagerStyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$(".drag_drop_grid").sortable({
items: 'tr:not(tr:first-child)',
cursor: 'crosshair',
connectWith: '.drag_drop_grid',
axis: 'y',
dropOnEmpty: true,
change: function (e, ui) {
var isExists = false;
if ($(this).attr("id") != ui.item.closest("table").attr("id")) {
$(this).find(".ItemId").each(function () {
if (!isExists) {
isExists = ui.item.find(".ItemId").html() == $(this).html();
}
});
if (isExists) {
$(".drag_drop_grid").sortable("cancel");
alert("Duplicate Item!");
} else {
$("<tr>" + ui.item.html() + "</tr>").insertAfter($('[id*=gvSource]').find("tbody").find('tr').eq($(ui.item).index() - 1));
}
}
}
});
$("[id*=gvDest] tr:not(tr:first-child)").remove();
});
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:HiddenField ID="hv_isChanged" runat="server" Value="false" />
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" TabStripPlacement="Top" AutoPostBack="true">
<ajaxToolkit:TabPanel ID="pnlTesting" runat="server" HeaderText="Testing">
<ContentTemplate>
<asp:GridView ID="gvSource" runat="server" CssClass="drag_drop_grid GridSrc" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="ItemId" HeaderText="Id" ItemStyle-CssClass="ItemId" />
<asp:BoundField DataField="Item" HeaderText="Item" />
<asp:BoundField DataField="Price" HeaderText="Price" />
</Columns>
</asp:GridView>
<hr />
<asp:GridView ID="gvDest" runat="server" CssClass="drag_drop_grid GridDest" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="ItemId" HeaderText="Id" ItemStyle-CssClass="ItemId" />
<asp:BoundField DataField="Item" HeaderText="Item" />
<asp:BoundField DataField="Price" HeaderText="Price" />
</Columns>
</asp:GridView>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajax:TabPanel ID="pnlBlah" runat="server" HeaderText="Blah">
<ContentTemplate>
<p>Testing</p>
</ContentTemplate>
</ajax:TabPanel>
</ajaxToolkit:TabContainer>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>