How to move datarow up and down in gridview using jquery in C# asp.net

Source code:-

  
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            $(".up, .down").click(function () {    // get parent tr  
                var $row = $(this).parents('tr:first'); var $link = $(this);
                // count all tr   
                var count = $('table tr').length;
                // if tr isn't the first 
                if ($row.index() !== 0) {      
                    if ($link.hasClass('up') && $row.index() > 1) {
                        $row.insertBefore($row.prev());
                    }       
                    else if ($link.hasClass('down') && $row.index() < count - 1) {
                        $row.insertAfter($row.next());
                    } var inputs = $("#myTable").find("tr").find("input");
                                  var ids = []; inputs.each(function () {
                        ids.push($(this).val());
                    });
                }
            });
        });
    </script>


//We just need to add templateField in grid view.

In gridview:-


<asp:TemplateField>
  <ItemTemplate>
           <a href="#" class="up">Up</a>
           <a href="#" class="down">Down</a>
   </ItemTemplate>
   </asp:TemplateField>


How to move datarow up and down in gridview using jquery in C# asp.net How to move datarow up and down in gridview using jquery in C# asp.net Reviewed by NEERAJ SRIVASTAVA on 12:38:00 PM Rating: 5

3 comments:

Powered by Blogger.