我正在使用jquery tablesorter,似乎无法使其工作。我已经让它在其他解决方案中工作,但似乎无法在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
当我去运行它并单击标题时,没有任何反应,但我无法弄清楚我哪里出错了。
谢谢!
答案 0 :(得分:0)
mmm,对我来说有两个可能的原因:
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();