Below is my aspx code:

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MoveableRecords.Default" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title>Make Grid View Records Moveable in ASP.NET using jQuery</title>
  6. <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
  7. <script src="jquery.tablednd.js" type="text/javascript"></script>
  8. <script type="text/javascript">
  9. $(function () {
  10. $("#gvEmployee").tableDnD();
  11. })
  12. </script>
  13. </head>
  14. <body>
  15. <form id="form1" runat="server">
  16. <table style="border: solid 15px blue; width: 100%; vertical-align: central;">
  17. <tr>
  18. <td style="padding-left: 50px; padding-top: 20px; padding-bottom: 20px; background-color: skyblue; font-size: 20pt; color: orangered;">Move Records in ASP.NET Grid View </td>
  19. </tr>
  20. <tr>
  21. <td style="text-align: left; padding-left: 50px; border: solid 1px red;">
  22. <asp:GridView ID="gvEmployee" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" CellSpacing="4">
  23. <AlternatingRowStyle BackColor="White" />
  24. <EditRowStyle BackColor="#2461BF" />
  25. <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
  26. <HeaderStyle BackColor="#507CD1" Font-Bold="true" ForeColor="White" />
  27. <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
  28. <RowStyle BackColor="#EFF3FB" Font-Names="Verdana" />
  29. <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
  30. <SortedAscendingCellStyle BackColor="#F5F7FB" />
  31. <SortedAscendingHeaderStyle BackColor="#6D95E1" />
  32. <SortedDescendingCellStyle BackColor="#E9EBEF" />
  33. <SortedDescendingHeaderStyle BackColor="#4870BE" />
  34. </asp:GridView>
  35. </td>
  36. </tr>
  37. </table>
  38. </form>
  39. </body>
  40. </html>
My aspx.cs code is:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Data.SqlClient;
  9. namespace MoveableRecords
  10. {
  11. public partial class Default : System.Web.UI.Page
  12. {
  13. SqlDataAdapter da;
  14. DataTable dt = new DataTable();
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. if (!Page.IsPostBack)
  18. BindGrid();
  19. }
  20. private void BindGrid()
  21. {
  22. SqlConnection con = new SqlConnection();
  23. con.ConnectionString = @"Server=INDIA\MSSQLServer2k8;database=EmployeeManagement;UID=sa; pwd=india;";
  24. SqlCommand cmd = new SqlCommand("SELECT * FROM EMPLOYEE", con);
  25. da = new SqlDataAdapter(cmd);
  26. da.Fill(dt);
  27. con.Open();
  28. cmd.ExecuteNonQuery();
  29. con.Close();
  30. if (!object.Equals(dt, null))
  31. {
  32. if (dt.Rows.Count > 0)
  33. {
  34. gvEmployee.DataSource = dt;
  35. gvEmployee.DataBind();
  36. }
  37. else
  38. {
  39. gvEmployee.DataSource = null;
  40. gvEmployee.DataBind();
  41. }
  42. }
  43. }
  44. }
  45. }
Now Run your application.



Now Select any records and do drag and drop.



Now,