gridview控件上的自定义分页

发布于 2024-09-14 05:30:59 字数 2415 浏览 3 评论 0原文

如果我删除 PagerSetting 或删除 PagerTemplate,下面的代码工作正常,所以如果我同时拥有(PagerSettingPagerTemplate )然后我的页码不显示。

我的问题是:如何在 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和PagerSetting。 PagerTemplate 并且如果我的 gridview 中有两个(PagerSetting 和 PagerTemplate),我的分页(1 2 3 4 5)不会显示,如果我删除 PagerTemplate 比我的分页显示(1 2 3 4 5 ...)有意义吗?

更新:

这是我想要得到的:

<< < 1 2 3 4 5 ..... > >> 找到的页面总数 80 - 页面 1/80 - 页面大小 {15,25,50,10}(这将是一个下拉列表)

below code works fine if i remove the PagerSetting or remove PagerTemplate so if i have both (PagerSetting & PagerTemplate) then my page number is not display.

my qeustion is: how can i display both (PagerTemplate and PagerSetting) togather at the bottom of the Gridview ? plese see the below source code.

<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>  

UPDATE 1:

I able to display paging 1 2 3 4 5... but the problem is: i can not have both PagerSetting & PagerTemplate and if i have both(PagerSetting & PagerTemplate) in my gridview my paging (1 2 3 4 5) is not displaying and if i remove PagerTemplate than my paging is displaying (1 2 3 4 5...) make sense?

UPDATE:

Here is what i am trying to get:

<< < 1 2 3 4 5 ..... > >> Total Pages Found 80 - Page 1/80 - PageSize {15,25,50,10} (this will be a dropdownlist)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉殇 2024-09-21 05:30:59

您可以使用以下代码来完成此操作

  1. 后端代码(gridview 的行创建事件):

    protected void GridView_RowCreated(对象发送者,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]) 是 LinkBut​​ton))
        {
            LinkBut​​ton btnPrev = (LinkBut​​ton)(tr.Cells[1]).Controls[0];
            if (btnPrev.Text == "...")
            {
                (((tr.Cells[1]).Controls[0]) as LinkBut​​ton).Text = "<";
            }
        }
        if (tr.Cells[tr.Cells.Count - 2] != null && (((tr.Cells[tr.Cells.Count - 2]).Controls[0]) 是 LinkBut​​ton))
        {
            LinkBut​​ton btnNext = (LinkBut​​ton)(tr.Cells[tr.Cells.Count - 2]).Controls[0];
            if (btnNext.Text == "...")
            {
                (((tr.Cells[tr.Cells.Count - 2]).Controls[0]) as LinkBut​​ton).Text = ">";
            }
        }
    }
    

    }

  2. 并使用 pagersetting 作为:

    >” >>
    

您将得到输出。 :)

注意:不要忘记设置网格的pageSizeAllowPaging ="true"

you can do this by using follow code

  1. Back end code ( row created event of 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. and use pagersetting as:

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

you will get your output. :)

Note: don't forgot to set pageSize and AllowPaging ="true" of grid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文