我对此有一个稍微不同的解决方案。我没有更改 DataPager 的呈现,而是稍微调整了标记,并且在呈现方面,它仍然看起来“类似引导程序”,即使它没有带有分页类的 UL/LI 标记。
一件非常重要的事情(如https://stackoverflow.com/a/19398488/1948625中所解释的)正在更改类 asp.net 输出以禁用控制,它默认为“aspNetDisabled”,但对于引导程序,最好简单地使用“禁用”。在 Global.asax 的 Application_Start 中执行此操作。如果您不这样做,则第一页、上一页、下一页和最后一页按钮不会显示为禁用。
void Application_Start(object sender, EventArgs e)
{
WebControl.DisabledCssClass = "customDisabledClassName";
}
来源:WebControl.DisabledCssClass 属性 (MSDN)
<asp:DataPager ID="it" runat="server" class="btn-group btn-group-sm">
<Fields>
<asp:NextPreviousPagerField PreviousPageText="<" FirstPageText="|<" ShowPreviousPageButton="true"
ShowFirstPageButton="true" ShowNextPageButton="false" ShowLastPageButton="false"
ButtonCssClass="btn btn-default" RenderNonBreakingSpacesBetweenControls="false" RenderDisabledButtonsAsLabels="false" />
<asp:NumericPagerField ButtonType="Link" CurrentPageLabelCssClass="btn btn-primary disabled" RenderNonBreakingSpacesBetweenControls="false"
NumericButtonCssClass="btn btn-default" ButtonCount="10" NextPageText="..." NextPreviousButtonCssClass="btn btn-default" />
<asp:NextPreviousPagerField NextPageText=">" LastPageText=">|" ShowNextPageButton="true"
ShowLastPageButton="true" ShowPreviousPageButton="false" ShowFirstPageButton="false"
ButtonCssClass="btn btn-default" RenderNonBreakingSpacesBetweenControls="false" RenderDisabledButtonsAsLabels="false"/>
</Fields>
</asp:DataPager>
上面的 Asp.net 服务器标记呈现为这个寻呼机:
这是呈现的 html:
<span id="ctl00_Body_CaseList918421504_ListControl_Pager_it" class="btn-group btn-group-sm">
<a class="disabled btn btn-default">|<</a>
<a class="disabled btn btn-default"><</a>
<span class="btn btn-primary disabled">1</span>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$Body$CaseList918421504_ListControl$Pager$it$ctl01$ctl01','')">2</a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$Body$CaseList918421504_ListControl$Pager$it$ctl01$ctl02','')">3</a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$Body$CaseList918421504_ListControl$Pager$it$ctl01$ctl03','')">4</a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$Body$CaseList918421504_ListControl$Pager$it$ctl01$ctl04','')">5</a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$Body$CaseList918421504_ListControl$Pager$it$ctl01$ctl05','')">6</a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$Body$CaseList918421504_ListControl$Pager$it$ctl01$ctl06','')">7</a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$Body$CaseList918421504_ListControl$Pager$it$ctl01$ctl07','')">8</a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$Body$CaseList918421504_ListControl$Pager$it$ctl01$ctl08','')">9</a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$Body$CaseList918421504_ListControl$Pager$it$ctl01$ctl09','')">10</a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$Body$CaseList918421504_ListControl$Pager$it$ctl01$ctl10','')">...</a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$Body$CaseList918421504_ListControl$Pager$it$ctl02$ctl00','')">></a>
<a class="btn btn-default" href="javascript:__doPostBack('ctl00$Body$CaseList918421504_ListControl$Pager$it$ctl02$ctl01','')">>|</a>
</span>