Click here to Skip to main content
13,000,135 members (56,972 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 19 Feb 2014

Move Up or Move Down GridView Rows using jQuery & ASP.NET, C#

, 19 Feb 2014
Rate this:
Please Sign up or sign in to vote.
Move up or Move down GridView rows using jQuery & ASP.NET, C#


Today, I am going to discuss how to move up or move down GridView row using jQUERY in ASP.NET.


The GridView is populated from code behind in Page_Load event and using jQuery we can re-order jQuery row. In every row of GridView, there will be UpArrow button and DownArrow button. Clicking UpArrow button, the associated row will be moved up and clicking DownArrow button, the associated row will be moved down.

Using the Code

Now, I am going to share step by step:

  1. Open Visual Studio. 
  2. Create one new Empty Web Project.
  3. Add a new file to your solution. Name it "Default.aspx".
  4. Add the following code in your "Default.aspx" (I have added necessary comments for understanding.)
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default"  %>
    <!DOCTYPE html>
    <html xmlns="">
    <head runat="server">
       <script type ="text/javascript" 
       src =""></script>
        <script type="text/javascript">
            var MoveRowUp = "table[id*=gvStudent] input[id*='btnUp']"; //Instance of MoveUp btn
            var MoveRowDown = "table[id*=gvStudent] input[id*='btnDown']";//Instance of MoveDown btn
            $(document).ready(function () {
                DisableRow(); //This function disables first and last row
                //This function Moves up the GridView row
                $(MoveRowUp).click(function () {               
                //This function Moves down the Gridview row
                $(MoveRowDown).click(function () {
                //This function disables first and last row
                function DisableRow() {
                    tr:has(td) input[id*='btnUp']").attr("disabled", false);
                    tr:has(td):first input[id*='btnUp']").attr("disabled", true);
                    tr:has(td) input[id*='btnDown']").attr("disabled", false);
                    tr:last input[id*='btnDown']").attr("disabled", true);
    <form id="form1" runat="server">
         <asp:GridView ID="gvStudent" runat="server" 
                <asp:BoundField DataField="SNAME" 
                HeaderText="Student Name" SortExpression="SNAME" />
                <asp:BoundField DataField="Class" 
                HeaderText="Student Class" SortExpression="Class" />
                <asp:TemplateField HeaderText="Move Row">
                       <input id="btnUp"  
                       type="button" value="&uArr;" 
                       style="color: Red;"/> &nbsp;
                        <input id="btnDown" 
                        type="button" value="&dArr;" 
                        style="color: Red;" />
  5. Add the following code in your code behind file - Default.aspx.cs (I have added necessary comments for understanding.)
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Data;
    public partial class Default : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            if (!this.IsPostBack)
                 LoadStudent(); //Populates GridView from Students table
        protected void LoadStudent()
            SqlConnection conn = new SqlConnection("YOUR CONNECTION STRING");
            SqlCommand cmd = new SqlCommand
            ("Select * from Students", conn); //Use your DB table name instead of Students
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet(); da.Fill
            gvStudent.DataSource = ds;
  6. Now your code is ready. Press F5 to run. Happy coding!!!

Points of Interest

For more information on jQuery, you can find online help at


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Asia/Pacific Region Asia/Pacific Region
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralNice but... Pin
Nitij Kumar21-Feb-14 1:50
professionalNitij Kumar21-Feb-14 1:50 
QuestionThis code is not working Pin
Asutosha20-Feb-14 8:29
memberAsutosha20-Feb-14 8:29 
AnswerRe: This code is not working Pin
Partha_sarathi_ghosh20-Feb-14 21:12
memberPartha_sarathi_ghosh20-Feb-14 21:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170624.1 | Last Updated 20 Feb 2014
Article Copyright 2014 by Partha_sarathi_ghosh
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid