title: How to sort item using <td> class inside ListView?
body: <p>I have a <code>ListView</code>. Inside that I am using <code>&lt;table&gt;</code> as item template. I want to sort the items using <code>&lt;td&gt;</code> class name.</p>
  
  <p>How can I do that? And this should work on button click.</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;asp:ListView ID="lstvRCGroupSource" runat="server" ViewStateMode="Disabled"&gt;
      &lt;LayoutTemplate&gt;
          &lt;ul id="list3" class="conn" style="width: 90%; height: 171px;"&gt;
              &lt;asp:PlaceHolder runat="server" ID="itemPlaceholder"&gt;&lt;/asp:PlaceHolder&gt;
          &lt;/ul&gt;
      &lt;/LayoutTemplate&gt;
      &lt;ItemTemplate&gt;
          &lt;li class="add" id="l3"&gt;
              &lt;table id="tbl" style="width: 100%;"&gt;
                  &lt;tr class="mytr" style="width: 100%;"&gt;
                      &lt;td class="border1" style="width: 50%;"&gt;&lt;%# Eval("code") %&gt;&lt;/td&gt;
                      &lt;td class="border2" style="width: 50%;"&gt;&lt;%# Eval("regon_name") %&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/li&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:ListView&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>function sortUnorderedList(ul, sortDescending) {
      if (typeof ul == "string")
          ul = document.getElementById(ul);
  
      var lis = ul.getElementsByTagName("li");
      var vals = [];
  
      for (var i = 0, l = lis.length; i &lt; l; i++)
          vals.push(lis[i].innerHTML);
  
      vals.sort();
  
      if (sortDescending)
          vals.reverse();
  
      for (var i = 0, l = lis.length; i &lt; l; i++)
          lis[i].innerHTML = vals[i];
  }
  
  window.onload = function () {
      var desc = false;
      document.getElementById("stCodeDSC").onclick = function () {
          sortUnorderedList("list3", desc);
          desc = !desc;
          return false;
      }
  }
  </code></pre>