title: ASP.NET drag and drop
body: <p>i am new with ASP.NET
  My task is create a drag and drop system.
  For now i am using up and down for each element of the page see the screen shot. How to manage the drag and drop with the same idea of ordering the objects?
  <a href="https://i.stack.imgur.com/mRmNh.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mRmNh.jpg" alt="Example image"></a></p>
  
  <p>And this is a code </p>
  
  <pre><code>protected void lb_up_Command(object sender, CommandEventArgs e) 
  { 
      ChangeItemNumber(int.Parse(e.CommandArgument.ToString()), -1); 
  } 
  protected void lb_down_Command(object sender, CommandEventArgs e) 
  { 
      ChangeItemNumber(int.Parse(e.CommandArgument.ToString()), 1); 
  }
  private void ChangeItemNumber(int id, int changeValue) 
  { 
      Dal dal = new Dal(); 
      var itemToChange = dal.GetSale(id); 
      Sale replacedLesson = null; 
      if (changeValue == -1) 
      { 
          for (int i = 0; i &lt; rp_sales.Items.Count; i++) 
          { 
              if (((HiddenField)rp_sales.Items[i].FindControl("hf_id")).Value == id.ToString()) 
              { 
              replacedLesson = dal.GetSale(int.Parse(((HiddenField)rp_sales.Items[i - 1].FindControl("hf_id")).Value)); 
              break; 
              } 
          } 
      } 
      else 
      { 
          for (int i = 0; i &lt; rp_sales.Items.Count; i++) 
          { 
              if (((HiddenField)rp_sales.Items[i].FindControl("hf_id")).Value == id.ToString()) 
              { 
                  replacedLesson = dal.GetSale(int.Parse(((HiddenField)rp_sales.Items[i + 1].FindControl("hf_id")).Value)); 
                  break; 
              } 
          } 
      //replacedLesson = dal.GetNextCategoryInLine((int)itemToChange.OrderNumber,chk_activeOnly.Checked); 
      }
  
      ViewState["main"] = itemToChange.ID; 
      ViewState["sub"] = replacedLesson.ID; 
  
      var num = (int)itemToChange.OrderNumber; 
      itemToChange.OrderNumber = replacedLesson.OrderNumber; 
      replacedLesson.OrderNumber = num; 
  
      // NormelizeLessonOrder(); 
      dal.Save(); 
      LoadData(); 
  }
  </code></pre>
  
  <p>ASPX Code</p>
  
  <pre><code>&lt;ItemTemplate&gt; 
  &lt;asp:Literal runat="server" ID="lit_tableRow"&gt;&lt;/asp:Literal&gt; 
  &lt;td&gt; 
  &lt;asp:HiddenField runat="server" ID="hf_counter" /&gt; 
  &lt;asp:HiddenField runat="server" ID="hf_id" /&gt; 
  &lt;asp:LinkButton OnClientClick="showLoad();" Font-Size="XX-Large" runat="server" ID="lb_up" OnCommand="lb_up_Command" CommandArgument='&lt;%# Eval("ID") %&gt;'&gt;&lt;span class="fa fa-2x fa-caret-up"&gt;&lt;/span&gt;&lt;/asp:LinkButton&gt; 
  &lt;asp:LinkButton OnClientClick="showLoad();" Font-Size="XX-Large" runat="server" ID="lb_down" OnCommand="lb_down_Command" 
  CommandArgument='&lt;%# Eval("ID") %&gt;'&gt;&lt;span class="fa fa-2x fa-caret-down"&gt;&lt;/span&gt;&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp; 
  &lt;/td&gt; 
  &lt;td&gt; 
  &lt;asp:Image runat="server" ID="img_logo" Height="50px" /&gt; 
  &lt;/td&gt; 
  &lt;td&gt; 
  &lt;asp:Label runat="server" ID="lbl_name" /&gt;&lt;br /&gt; 
  &lt;asp:Label runat="server" ID="lbl_Status"&gt;&lt;/asp:Label&gt; 
  &lt;/td&gt; 
  &lt;td&gt; 
  &lt;asp:Label runat="server" ID="lbl_Title" Font-Bold="true" /&gt;&lt;br /&gt; 
  &lt;asp:Label runat="server" ID="lbl_data" Font-Size="Small"&gt;&lt;/asp:Label&gt; 
  &lt;/td&gt; 
  &lt;td&gt; 
  &lt;asp:Label runat="server" ID="lbl_category"&gt;&lt;/asp:Label&gt; 
  &lt;/td&gt; 
  &lt;td&gt; 
  &lt;asp:Label runat="server" ID="lbl_totalSales"&gt;&lt;/asp:Label&gt; 
  &lt;/td&gt; 
  &lt;td&gt; 
  &lt;asp:Literal runat="server" ID="lit_view"&gt;&lt;/asp:Literal&gt; 
  &lt;/td&gt; 
  &lt;/tr&gt; 
  &lt;/ItemTemplate&gt;
  </code></pre>