簡體   English   中英

gridview控件上的自定義分頁

[英]custom paging on gridview control

下面的代碼工作正常,如果我刪除PagerSetting或刪除PagerTemplate所以如果我同時( PagerSettingPagerTemplate )然后我的頁碼不顯示。

我的qeustion是:我如何在Gridview的底部顯示(PagerTemplate和PagerSetting )? 請參閱以下源代碼。

<asp:GridView ID="gvTable" runat="server" ShowHeader="true"     
  PageSize="5" AllowPaging="true" AllowSorting="true"     
  DataSourceID="myLinqDataSource" AutoGenerateColumns="false"     
  OnRowDataBound="GridView_DataBound">     
  <Columns>     
    <asp:BoundField DataField="Edited" HeaderText="Date" DataFormatString="{0:d}" />     
    <asp:BoundField DataField="Activity" HeaderText="Notes" />     
  </Columns>     
<PagerStyle CssClass="pager-row" />    
                    <RowStyle CssClass="row" />    
                    <PagerSettings Mode="NumericFirstLast" PageButtonCount="7" FirstPageText="«" LastPageText="»" />    
                   **<PagerTemplate>**     
                        <div style="float: left; margin-left: 12px;">    
                            <div style="float: left; margin: 4px 6px 0px 0px;">Page Size</div>    
                            <asp:DropDownList ID="ddlPageSizeChange" runat="server" AutoPostBack="true" OnSelectedIndexChanged="PageSizeChange">    
                                <asp:ListItem>15</asp:ListItem>    
                                <asp:ListItem>25</asp:ListItem>    
                                <asp:ListItem>50</asp:ListItem>    
                                <asp:ListItem>100</asp:ListItem>    
                            </asp:DropDownList>    
                        </div>    
                        <div class="gridCount" runat="server" id="divGridCount"><b>1</b> Items Found  </div>    
                    </PagerTemplate>      
</asp:GridView>  

更新1:

我能夠顯示分頁1 2 3 4 5 ...但問題是:我不能同時擁有PagerSetting和PagerTemplate,如果我在gridview中同時擁有(PagerSetting和PagerTemplate)我的分頁(1 2 3 4 5)不是顯示,如果我刪除PagerTemplate比我的分頁顯示(1 2 3 4 5 ...)有意義嗎?

更新:

這是我想要得到的:

<< <1 2 3 4 5 .....> >> 找到的總頁數80 - 第1/80頁 - PageSize {15,25,50,10}(這將是一個下拉列表)

你可以使用以下代碼來做到這一點

  1. 后端代碼(gridview的行創建事件):

     protected void GridView_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Pager) { TableRow tr = (TableRow)e.Row.Cells[0].Controls[0].Controls[0]; if (tr.Cells[1] != null && (((tr.Cells[1]).Controls[0]) is LinkButton)) { LinkButton btnPrev = (LinkButton)(tr.Cells[1]).Controls[0]; if (btnPrev.Text == "...") { (((tr.Cells[1]).Controls[0]) as LinkButton).Text = "<"; } } if (tr.Cells[tr.Cells.Count - 2] != null && (((tr.Cells[tr.Cells.Count - 2]).Controls[0]) is LinkButton)) { LinkButton btnNext = (LinkButton)(tr.Cells[tr.Cells.Count - 2]).Controls[0]; if (btnNext.Text == "...") { (((tr.Cells[tr.Cells.Count - 2]).Controls[0]) as LinkButton).Text = ">"; } } } 

    }

  2. 並使用pagersetting:

     <PagerSettings Mode="NumericFirstLast" FirstPageText="<<" LastPageText=">>" /> 

你會得到你的輸出。 :)

注意:不要忘記設置網格的pageSizeAllowPaging =“true”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM