我得到了错误:
Cannot call method 'getElementsByTagName' of null.
警报#1弹出,警报#2弹出,但显然要么创建gvHeader
,要么调用构建标题失败,我从未看到警报#3。
我还尝试在#<%
和"dummyHeader"
之前和之后放置"th"
。我也试过了"TH"
。
注意,我正在尝试关注this suggestion。我没有成功地从作者或该网站上的任何其他人那里获得任何帮助。
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Main.Master" AutoEventWireup="true" CodeBehind="CraigTest.aspx.cs" Inherits="OfficeIntranet.Forms.Purchasing.CraigTest" %>
<%@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit,
Version=4.1.51116.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.tablesorter.js" type="text/javascript"></script>
<link href="../../Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$("#<%=gvOrderDetails.ClientID%>").tablesorter();
alert("Are we here 1?");
SetDefaultSortOrder();
alert("Are we here 4?");
});
function Sort(cell, sortOrder) {
var sorting = [[cell.cellIndex, sortOrder]];
$("#<%=gvOrderDetails.ClientID%>").trigger("sorton", [sorting]);
if (sortOrder == 0) {
sortOrder = 1;
cell.className = "sortDesc";
}
else {
sortOrder = 0;
cell.className = "sortAsc";
}
cell.setAttribute("onclick", "Sort(this, " + sortOrder + ")");
cell.onclick = function () { Sort(this, sortOrder); };
document.getElementById("container").scrollTop = 0;
}
function SetDefaultSortOrder() {
var gvHeader = document.getElementById("dummyHeader");
alert("Are we here 2?");
var headers = gvHeader.getElementsByTagName("th");
alert("Are we here 3?");
for (var i = 0; i < headers.length; i++) {
headers[i].setAttribute("onclick", "Sort(this, 1)");
headers[i].onclick = function () { Sort(this, 1); };
headers[i].className = "sortDesc";
}
}
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolderBody" runat="server">
<asp:UpdatePanel ID="UpdatePanelSPA" runat="server" UpdateMode="Always">
<ContentTemplate>
<div id="headerE" runat="server" style="text-align: center; width: auto;">
<asp:Label ID="MainH" CssClass="headerText" runat="server">SPA Order Control</asp:Label>
<asp:Label ID="headVersion" CssClass="textarea" runat="server"></asp:Label>
</div>
<asp:Panel ID="PanelDetails" runat="server" Width="960px" Style="margin-left: 20px;" Visible="false">
<div class="container" id="DetailsSection">
<div>
<table class="tablesorter" id="dummyHeader" rules="all"; style="width:940px; height:25px; border-collapse:collapse">
<col style="width:78px" />
<col style="width:225px" />
<tr style="background-color: LightGrey; height:25px; font-weight:bold; border-width:1px; border-color:Gray"/>
<th scope="col">Item Code</th>
<th scope="col">Description</th>
</tr>
</table>
<div style="height:550px; width:942px; overflow:auto;">
<asp:GridView ID="gvOrderDetails" runat="server" ShowHeader="false"
AlternatingRowStyle-BackColor="#FAFAFA" Width="924px"
AutoGenerateColumns="False" AllowSorting="True" OnSorting="SortOrderDetails"
OnRowCommand="gvOrderDetails_RowCommand" EmptyDataText="No Data to Display"
DataKeyNames="STOREORDNUM" HeaderStyle-Height="22px"
onselectedindexchanged="gvOrderDetails_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF"/>
<FooterStyle BackColor="LightGray" Font-Bold="False" ForeColor="Black" />
<HeaderStyle BackColor="LightGray" Font-Bold="False" ForeColor="Black" BorderWidth="1px" BorderColor="Gray"/>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" Height="22px"/>
<Columns>
<asp:BoundField DataField="ITMCD" HeaderText="Item Code" >
<ItemStyle CssClass="gvAlignCenter5pxR" Width="78px" />
</asp:BoundField>
<asp:BoundField DataField="DESC" HeaderText="Description" >
<ItemStyle CssClass="gvAlignLeft5pxR" Width="232px"/>
</asp:BoundField>
</Columns>
</asp:GridView>
</div>
</div>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>