title: How to shuffle or reorder rows in the gridview on button click
body: <p>I have radgrid for which I have binded data from code behind, I have two buttons next to my grid control, one  moveup button and   movedown button.  On selecting a particular row on the grid and on click of moveup button I have to move the row up. How do I exchange the rows?</p>
  
  <p>I am trying to implement the following code, but for some reason my MoveRowUp() and MoveRowDown() events are not firing in the javascript.</p>
  
  <pre><code>&lt;head runat="server"&gt;  
      &lt;title&gt;Untitled Page&lt;/title&gt; 
      &lt;script type="text/javascript"&gt;  
                  var SelectedRow;  
                  function RowSelected(rowObject)  
                  {  
                      SelectedRow = rowObject;  
                  }  
  
                  function MoveRowUp()  
                  {  
                      if (SelectedRow &amp;&amp; SelectedRow.Control.sectionRowIndex &gt; 0)  
                      {  
                          SerializeReorderChanges(SelectedRow.Control.sectionRowIndex, SelectedRow.Control.sectionRowIndex - 1);  
                          SelectedRow.Control.swapNode(SelectedRow.Control.parentNode.rows[SelectedRow.Control.sectionRowIndex - 1]);  
                      }  
                  }  
  
                  function MoveRowDown()  
                  {  
                      if (SelectedRow &amp;&amp; SelectedRow.Control.sectionRowIndex &lt; SelectedRow.Control.parentNode.rows.length - 1)  
                      {  
                          SerializeReorderChanges(SelectedRow.Control.sectionRowIndex, SelectedRow.Control.sectionRowIndex + 1);  
                          SelectedRow.Control.parentNode.rows[SelectedRow.Control.sectionRowIndex + 1].swapNode(SelectedRow.Control);  
                      }  
                  }  
  
                  function SerializeReorderChanges(index1, index2)  
                  {  
                      var reorderInput = document.getElementById("ReorderChanges");  
                      if (reorderInput)  
                      {  
                          reorderInput.value += index1 + "," + index2 + ";";  
                      }  
                  }  
  
                  if(window.netscape)  
                  {  
                      Node.prototype.swapNode = function(node)   
                      {  
                          var nextSibling = this.nextSibling;  
                          var parentNode = this.parentNode;  
                          node.parentNode.replaceChild(this, node);  
                          parentNode.insertBefore(node, nextSibling);  
                      }  
                  }  
      &lt;/script&gt; 
  &lt;/head&gt; 
  &lt;body&gt; 
      &lt;form id="form1" runat="server"&gt;  
          &lt;div&gt; 
              &lt;input type="hidden" name="ReorderChanges" id="ReorderChanges"&gt;  
              &lt;input type="button" value="Move selected row up" onclick="MoveRowUp()"&gt;  
              &lt;br /&gt; 
              &lt;input type="button" value="Move selected row down" onclick="MoveRowDown()"&gt;  
              &lt;radG:RadGrid ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" runat="server"&gt;  
                  &lt;ClientSettings&gt; 
                      &lt;Selecting AllowRowSelect="True"&gt;&lt;/Selecting&gt; 
                      &lt;ClientEvents OnRowSelected="RowSelected"&gt;&lt;/ClientEvents&gt; 
                  &lt;/ClientSettings&gt; 
              &lt;/radG:RadGrid&gt; 
              &lt;input type="button" value="Apply changes server side" onclick="__doPostBack('&lt;%= RadGrid1.ClientID %&gt;','ReorderedRows:' + document.getElementById('ReorderChanges').value);"&gt;  
          &lt;/div&gt; 
      &lt;/form&gt; 
  &lt;/body&gt; 
  &lt;/html&gt; 
  </code></pre>