2012-01-12 41 views
0

我有以下PagerTemplate。當用戶查看第一頁時,我需要隱藏上一個鏈接,如果用戶正在查看最後一頁,則隱藏下一個鏈接。GridView自定義PagerTemplate,顯示隱藏上一個和下一個鏈接

   <PagerTemplate> 
        <table border="0" style="width: 100%;"> 
         <tbody> 
          <tr> 
           <td style="float: right;"> 
            <asp:LinkButton CommandName="Page" CommandArgument="Prev" ID="LinkButton2" runat="server"><< Previous</asp:LinkButton> 
            &nbsp;<asp:LinkButton CommandName="Page" CommandArgument="Next" ID="LinkButton3" runat="server" >Next >></asp:LinkButton> 
           </td> 
           <td style="clear: both"></td> 
          </tr> 
         </tbody> 
        </table> 
       </PagerTemplate> 

回答

3

電網的PageIndexPageCount屬性將幫助你在這裏 - 上一個鏈接應該顯示/時PageIndex > 0而下一環節應顯示/啓用,只有當PageIndex < PageCount - 1纔會啓用。

使用行創建的事件來查找控件並更改可見性。例如,

protected void GridView_RowCreated(Object sender, GridViewRowEventArgs e) 
{ 
    if(e.Row.RowType == DataControlRowType.Pager) 
    { 
     var prev = (LinkButton)e.Row.FindControl("LinkButton2"); 
     prev.Visible = Grid.PageIndex > 0; 

     var next = (LinkButton)e.Row.FindControl("LinkButton3"); 
     next.Visible = Grid.PageIndex < grid.PageCount - 1; 
    } 
} 

我不確定您是否需要當前用戶界面的自定義模板。您可以使用尋呼機設置 - 例如,

<pagersettings mode="NextPrevious" 
      nextpagetext="Next >>" 
      previouspagetext="<< Previos" 
      position="Bottom"/> 

並使用PagerStyle進行UI設計。

<PagerStyle CssClass="myPager" /> 
+0

感謝您的幫助 – user960567 2012-01-12 09:32:19

相關問題