2

我正在使用 jquery 表排序器,但似乎无法正常工作。我已经让它在其他解决方案中工作,但似乎无法在 HTML5 项目中复制它。

以下代码位于母版页的标题中;

<script type="text/javascript" src="TableSorter/jquery-latest.js"></script>
<script type="text/javascript" src="TableSorter/jquery.tablesorter.js"></script>
<script type="text/javascript" src="TableSorter/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="TableSorter/jquery.metadata.js"></script>
<script type="text/javascript" src="TableSorter/jquery.tablesorter.pager.js" ></script>

同样在母版页中,我放置了 Jquery。该表是动态创建的,名称为“ctl00_ContentPlaceHolder1_memberTable”

<script type="text/javascript">
    $(document).ready(function () {
        $("#ctl00_ContentPlaceHolder1_memberTable").tablesorter();
    });
</script>

前端代码:

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/SSASWeb.Master"
    CodeBehind="MemberList.aspx.vb" Inherits="SSASWeb_HTML5.MemberList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h2>
        Member List
    </h2>
    <div id="table" runat="server" style="margin-right: 50px" class="tablesorter">
    </div>
</asp:Content>

填充表格的代码:

Dim ScriptManager As ClientScriptManager = Page.ClientScript
        Dim t As Table = HtmlHelper.ConvertToHtmlTable(ds.Tables(0))
        Dim i As Integer = 0
        For Each row As TableRow In t.Rows
          If i = 0 Then
            i = i + 1
            Continue For
          End If
          Dim strMemNo As String = row.Cells(0).Text
          row.Cells(0).Text = ""
          Dim a As New HtmlAnchor()
          a.HRef = "NameAndAddress.aspx?member=" + strMemNo
          a.InnerText = strMemNo
          row.Cells(0).Controls.Add(a)
        Next
        t.ID = "memberTable"
        table.Controls.Add(t)

我在后端代码的调用中调用的函数:

Public Shared Function ConvertToHtmlTable(dt As DataTable) As Table
    Dim table As New Table()
    table.CssClass = "hovered tablesorter"
    Dim tHead As New TableRow()
    tHead.TableSection = TableRowSection.TableHeader
    For Each col As DataColumn In dt.Columns
      Dim cell As New TableCell()
      cell.Text = col.ColumnName
      tHead.Cells.Add(cell)
    Next
    table.Rows.Add(tHead)
    For Each row As DataRow In dt.Rows
      Dim tBodyRow As New TableRow()
      tBodyRow.TableSection = TableRowSection.TableBody
      For Each cell In row.ItemArray
        Dim rowCell As New TableCell()
        If Not IsDBNull(cell) Then
          Dim dtValue As DateTime
          If DateTime.TryParse(cell, dtValue) Then
            rowCell.Text = dtValue.ToShortDateString()
          Else
            rowCell.Text = cell
          End If
        End If
        tBodyRow.Cells.Add(rowCell)
      Next
      table.Rows.Add(tBodyRow)
    Next
    Return table
  End Function

当我去运行它并单击标题时,没有任何反应,但我无法弄清楚我哪里出错了。

谢谢!

4

1 回答 1

0

嗯,对我来说有两个可能的原因:

1º 不要使用:

<script type="text/javascript" src="TableSorter/jquery.tablesorter.js"></script>

<script type="text/javascript" src="TableSorter/jquery.tablesorter.min.js"></script>

同时,只选择一个。

2º 你可以使用

$("[id$=memberTable]").tablesorter();
于 2013-04-11T14:15:19.193 回答