none
gridview 分页问题 RRS feed

  • 问题

  •  <PagerTemplate>
                                                                                <table width="100%" >
                                                                                    <tr>
                                                                                        <td style="text-align: right"  >
                                                                                            <div style="text-align: right; color: #053d90; font-weight: normal; ">
                                                                                                共<%# ((System.Data.DataSet)((GridView)Container.Parent.Parent).DataSource).Tables[0].Rows.Count%>条记录。
                                                                                                共<asp:Label ID="lblPageCount" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>'
                                                                                                    ForeColor="#053D90" Font-Bold="False" Font-Strikeout="False" Font-Underline="False" />页。
                                                                                                <!--下面的首页,上一页,下一页,尾页可以换成相应的ImageButton形式-->
                                                                                                <asp:ImageButton ID="btnFirst" runat="server" CausesValidation="False" CommandArgument="First"
                                                                                                    CommandName="Page" Text="首页" ImageUrl="~/images/send_items_page_arrow_first.gif" />
                                                                                                <asp:ImageButton ID="btnPrev" runat="server" CausesValidation="False" CommandArgument="Prev"
                                                                                                    CommandName="Page" Text="上一页" ImageUrl="~/images/send_items_page_arrow_l.gif" />
                                                                                                <asp:Label ID="labPageindex" runat="server" Text='<%# GetPages(10) %>'  ForeColor="#053D90" Font-Underline="false" ></asp:Label>&nbsp;
                                                                                                <asp:ImageButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next"
                                                                                                    CommandName="Page" Text="下一页" ImageUrl="~/images/send_items_page_arrow_r.gif" />
                                                                                                <asp:ImageButton ID="btnLast" runat="server" CausesValidation="False" CommandArgument="Last"
                                                                                                    CommandName="Page" Text="尾页" ImageUrl="~/images/send_items_page_arrow_end.gif" />
                                                                                                转到:
                                                                                                <asp:TextBox ID="txtNewPageIndex" runat="server" Width="28px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1  %>'
                                                                                                    Height="14px" />
                                                                                                <asp:ImageButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1"
                                                                                                    CommandName="PageGo" Text="GO" ImageUrl="~/images/send_items_page_arrow_go.gif" />
                                                                                                <div>
                                                                                                </div>
                                                                                        </td>
                                                                                    </tr>
                                                                                </table>
                                                                            </PagerTemplate>
    CS文件:

      protected void gvSms_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

            GridView theGrid = sender as GridView;
            int newPageIndex = 0;
            newPageIndex = e.NewPageIndex;
            newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
            newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;

            theGrid.PageIndex = newPageIndex;

            BindGv(gvSms.PageIndex);
         
        }
        protected string GetPages(int pageslen)
        {
            string pages = "";
            int mod = 0;
            int div = Math.DivRem(gvSms.PageIndex, pageslen, out mod);
            int len = pageslen;
            if (div * pageslen + pageslen > gvSms.PageCount) len = gvSms.PageCount - div * pageslen;
            for (int i = 0; i < len; i++)
            {
                pages += "<a href='?pindex=" + (div * pageslen + i + 1).ToString() + "'>" + (div * pageslen + i + 1).ToString() + "</a>  ";
            }
            if (div * pageslen + len != gvSms.PageCount)
            {
                pages += "<a href='?pindex=" + (div * pageslen + pageslen + 1).ToString() + "'></a>  ";
            }
            return pages;
        }

    2010年2月10日 9:58

答案

  • 你好,

    你是采用上页下页这样的方式做的,怎么让当前页没有下划线,其它页有呢。你的当前页是哪个呢。当前页是第二页的时候哪个表示当前页,没有“2”这个数字啊。你都是上页下页这样的方式。

    除了首页和尾页可以实现你的下划线问题外,其它的都不行。另外ImageButton是没有Text属性的。
    怎么实现你可以使用下面的锚点方式。在你输出“首页”或尾页的地方采用下面这种方式。


     <%Response.Write("<a href=\"javascript:__doPostBack('GridViewId','Page$1')\">首页</a>");%>
    
     <%Response.Write(string.Format("<a href=\"javascript:__doPostBack('GridViewId','Page${0}')\">尾页</a>", this.GridViewId.PageCount));%>
    
    然后加上我上面的那个样式:
    a:active
    {
      text-decoration:none;
    }


    Microsoft Online Community Support
    2010年2月16日 2:30

全部回复

  • 就是在当前页没有下划线,其他页有下划线。这个效果

    2010年2月11日 1:42
  • 你好,

    我这边GridView默认的就是这个效果啊。
    Microsoft Online Community Support
    2010年2月11日 2:18
  • 我是自己在 <PagerTemplate>写的代码...,如何变成默认的

    2010年2月11日 4:49
  • 用下面的样式试试,假设你的那些数字都是连接。
    a:active
    {
      text-decoration:none;
    }

    Microsoft Online Community Support
    2010年2月11日 5:01
  • 你好,
    你直接把代码贴在论坛就可以了,大伙一起帮你看看,这样大伙都可以帮助你。


    Microsoft Online Community Support
    2010年2月11日 5:17
  • 你好,

    你是采用上页下页这样的方式做的,怎么让当前页没有下划线,其它页有呢。你的当前页是哪个呢。当前页是第二页的时候哪个表示当前页,没有“2”这个数字啊。你都是上页下页这样的方式。

    除了首页和尾页可以实现你的下划线问题外,其它的都不行。另外ImageButton是没有Text属性的。
    怎么实现你可以使用下面的锚点方式。在你输出“首页”或尾页的地方采用下面这种方式。


     <%Response.Write("<a href=\"javascript:__doPostBack('GridViewId','Page$1')\">首页</a>");%>
    
     <%Response.Write(string.Format("<a href=\"javascript:__doPostBack('GridViewId','Page${0}')\">尾页</a>", this.GridViewId.PageCount));%>
    
    然后加上我上面的那个样式:
    a:active
    {
      text-decoration:none;
    }


    Microsoft Online Community Support
    2010年2月16日 2:30