0

我已经像这样动态地创建了 html 表。现在我想在客户端单击名称标题时根据名称对表格进行排序。我怎样才能做到这一点?

        StringBuilder sb = new StringBuilder();
        sb.Append("<table border='1' id='tblCustomers'>");

        sb.Append("<tr>");

        sb.Append("<th>");
        sb.Append("Name");
        sb.Append("</th>");

        sb.Append("<th>"); 
        sb.Append("City");
        sb.Append("</th>");          


        sb.Append("</tr>");
        for(int i=0; i< dtcustomers.count;i++)
        {
           sb.Append("<tr>");

           sb.Append("<td>");
           sb.Append(dtcustomers.Rows[i]["Name"]);
           sb.Append("</td>");

           sb.Append("<td>");
           sb.Append(dtcustomers.Rows[i]["City"]);
           sb.Append("</td>");

           sb.Append("</tr>");
        }

         sb.Append("</table>");
         this.mydiv.InnerHtml = sb.ToString();
4

2 回答 2

4

由于您使用的是 jQuery 并希望在客户端完成此操作,您可以试试这个方便的插件

于 2012-12-12T06:56:35.023 回答
0

这也非常有用:https ://www.kryogenix.org/code/browser/sorttable/

它为您提供了一个要安装的 js 库,您所要做的就是将其链接到您的项目<script src="sorttable.js"></script>并将一个类添加到您的表中。真的很容易。

于 2018-06-19T12:36:25.403 回答