我在我的ASP.Net WebForms應用程序的一個頁面上有一個正確的工作asp:GridView
,並且在另一個頁面上的一個非常類似的頁面不工作。問題在於分頁;我在asp:GridView
控件上有AllowPaging=true
,並在代碼隱藏中正確設置了OnPageIndexChanging="searchResultsGridView_PageIndexChanging"
方法。運行時,分頁顯示正確(即使使用我在PagerStyle
上的自定義css),但後續頁面的編號鏈接按鈕沒有在生成的標記中設置任何href=""
。ASP.NET(4.5)GridView分頁HTML標記缺失href鏈接
這裏是生成的標記:
<tr align="center" class="gridViewPager">
<td colspan="10">
<table>
<tbody>
<tr>
<td>
<span>1</span>
</td>
<td>
<a>2</a>
</td>
<td>
<a>3</a>
</td>
<td>
<a>4</a>
</td>
<td>
<a>5</a>
</td>
<td>
<a>6</a>
</td>
<td>
<a>7</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
顯然,應該對<a>
標籤的href=""
屬性每個<td>
但沒有。下面是來自具有正常工作分頁asp:GridView
頁面的標記:
<td><a href="javascript:__doPostBack('ctl00$ModalPanelContentPlaceholder$designerSearchResultsGridView','Page$2')">2</a></td>
這裏是我的.aspx代碼:
<div id="searchResultsTableGridViewDivContainer" runat="server">
<asp:GridView CssClass="table table-hover table-bordered" ID="searchResultsGridView"
AutoGenerateColumns="false" SelectedRowStyle-CssClass="info"
OnRowDataBound="searchResultsGridView_RowDataBound"
OnSelectedIndexChanged="searchResultsGridView_SelectedIndexChanged" AllowPaging="true"
PageSize="15" OnPageIndexChanging="searchResultsGridView_PageIndexChanging"
runat="server">
<Columns>
<asp:BoundField HeaderText="Tracking #" DataField="TrackingNumber" />
<asp:BoundField HeaderText="Product Type" DataField="ProductType.TypeName" />
<asp:BoundField HeaderText="Design Type" DataField="DesignType.TypeName" />
<asp:BoundField HeaderText="PWA #" DataField="PWAProductNumber" />
<asp:BoundField HeaderText="PWB #" DataField="PWBProductNumber" />
<asp:BoundField HeaderText="Rev" DataField="Revision" />
<asp:BoundField HeaderText="Designers" DataField="DesignersCSV" />
<asp:BoundField HeaderText="Status" DataField="Status.StatusName" />
<asp:BoundField HeaderText="# Times Released" DataField="NumTimesReleased" />
<asp:BoundField HeaderText="Queue Date" DataField="FormattedQueueDate" />
</Columns>
<PagerStyle HorizontalAlign="Center" CssClass="gridViewPager" />
</asp:GridView>
</div>
而且我的相關代碼隱藏:
/// <summary>
/// EVENT HANDLER: Handles the RowDataBound event of the customerSearchResultsGridView control.
///
/// Allow the entire row to be clicked as a "Selector".
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="GridViewRowEventArgs"/> instance containing the event data.</param>
protected void searchResultsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onclick"] =
ClientScript.GetPostBackClientHyperlink(searchResultsGridView, "Select$" + e.Row.RowIndex);
}
}
protected void searchResultsGridView_SelectedIndexChanged(object sender, EventArgs e)
{
aboutProductBtnPanel.Enabled = (searchResultsGridView.SelectedRow == null) ? false : true;
}
/// <summary>
/// EVENT HANDLER: Handles the PageIndexChanging event of the searchResultsGridView control.
///
/// Increment the next page of the GridView for results > 15.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="GridViewPageEventArgs"/> instance containing the event data.</param>
protected void searchResultsGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
searchResultsGridView.PageIndex = e.NewPageIndex;
// don't refetch the data, just get it from the session
searchResultsGridView.DataSource = SessionWrapper.Current.CaptureProductSearchResults;
searchResultsGridView.DataBind();
// new page, clear the selection
searchResultsGridView.SelectedIndex = -1;
aboutProductBtnPanel.Enabled = false;
}
任何想法爲什麼自動生成的HTML標記無法添加href鏈接?
只是爲了比較,你還可以發佈工作GridView的標記? – Andrei
什麼是您的searchFormView對象?您對searchResultsGridView的所有其他引用都沒有此前綴。你可以嘗試刪除它在這一行:'searchFormView.SearchResultsGridView.DataBind();' – gotmilk13531
啊,@ gotmilk13531,因爲我的應用程序遵循MVP設計,所以我最初在外部演示者類中擁有searchResultsGridView_PageIndexChanging()方法的內容模式。爲了簡化顯示的代碼,我將外部演示者的輔助方法的內容從代碼隱藏複製到事件方法中,但忘記擺脫演示者所看到的視圖的句柄。對於這個問題抱歉,但是searchFormView不應該,也不會涉及這個問題。我自更新了代碼以反映這一點。 – bradykey