Thursday, 27 March 2014

Drag Drop GridView Rows With JQuery Asp.Net

This Example explains How To Implement Drag And Drop GridView Rows Functionality Using JQuery JavaScript In Asp.Net 2.0 3.5 4.0 To Rearrange Row On Client Side.

You need to download and add JQuery and TableDnD plugin in your application.

GridView is populated with Northwind database using SqlDataSource.





Add Script references and css style in head section of page.


   <style type="text/css">
       .highlight
         {
            color : White !important;
             background-color : Teal !important;
         }
   </style>
     <script src="jquery-1.7.1.js" type="text/javascript"/>
    <script src="jquery.tablednd.0.7.min.js" type="text/javascript"/>

Call tableDnD function of drag and drop plugin by passing Gridview Id.


    <script type="text/javascript" language="javascript">
     $(document).ready(function() 
     {
     $("#<%=GridView1.ClientID%>").tableDnD(
                 {
                     onDragClass: "highlight"
                 });
     });
     </script>
    </head>



     <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                   AutoGenerateColumns="False" DataKeyNames="OrderID" 
                   DataSourceID="SqlDataSource1">
     <Columns>
     <asp:BoundField DataField="OrderID" HeaderText="OrderID"/>
     <asp:BoundField DataField="Freight" HeaderText="Freight"/>
     <asp:BoundField DataField="ShipName" HeaderText="ShipName"/>
     <asp:BoundField DataField="ShipCity" HeaderText="ShipCity"/>
     <asp:BoundField DataField="ShipCountry" HeaderText="ShipCountry"/>
    </Columns>
    </asp:GridView>


Build and run the code. 

No comments:

Post a Comment