Hi janalee64,
Refer below sample code for your reference.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.GridSrc td
{
background-color: #A1DCF2;
color: black;
font-size: 10pt;
font-family: Arial;
line-height: 200%;
cursor: pointer;
width: 100px;
}
.GridSrc th
{
background-color: #3AC0F2;
color: White;
font-family: Arial;
font-size: 10pt;
line-height: 200%;
width: 100px;
}
.GridDest td
{
background-color: #eee !important;
color: black;
font-family: Arial;
font-size: 10pt;
line-height: 200%;
cursor: pointer;
width: 100px;
}
.GridDest th
{
background-color: #6C6C6C !important;
color: White;
font-family: Arial;
font-size: 10pt;
line-height: 200%;
width: 100px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<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>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script>
<link rel="Stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/redmond/jquery-ui.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>
</div>
</form>
</body>
</html>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("ItemId"), new DataColumn("Item"), new DataColumn("Price") });
dt.Rows.Add(1, "Shirt", 450);
dt.Rows.Add(2, "Jeans", 3200);
dt.Rows.Add(3, "Trousers", 1900);
dt.Rows.Add(4, "Tie", 185);
dt.Rows.Add(5, "Cap", 100);
dt.Rows.Add(6, "Hat", 120);
dt.Rows.Add(7, "Scarf", 290);
dt.Rows.Add(8, "Belt", 150);
gvSource.UseAccessibleHeader = true;
gvSource.DataSource = dt;
gvSource.DataBind();
dt.Rows.Clear();
dt.Rows.Add();
gvDest.DataSource = dt;
gvDest.DataBind();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(2) {New DataColumn("ItemId"), New DataColumn("Item"), New DataColumn("Price")})
dt.Rows.Add(1, "Shirt", 450)
dt.Rows.Add(2, "Jeans", 3200)
dt.Rows.Add(3, "Trousers", 1900)
dt.Rows.Add(4, "Tie", 185)
dt.Rows.Add(5, "Cap", 100)
dt.Rows.Add(6, "Hat", 120)
dt.Rows.Add(7, "Scarf", 290)
dt.Rows.Add(8, "Belt", 150)
gvSource.UseAccessibleHeader = True
gvSource.DataSource = dt
gvSource.DataBind()
dt.Rows.Clear()
dt.Rows.Add()
gvDest.DataSource = dt
gvDest.DataBind()
End If
End Sub
Screenshot