• girdview 分页PageIndexChanging


    修改方法:一要在girdview 后面加 OnPageIndexChanging="GridView1_PageIndexChanging

                    二要cs页面中添加

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

        {

            GridView1.PageIndex = e.NewPageIndex;

            DataBind();

        }

     OK问题解决!!

      下面的是一个比较齐全的分页代码, 

     protected void Page_Load(object sender, EventArgs e)

        {

            btnFirst.Text = "最首页";

            btnPrev.Text = "前一页";

            btnNext.Text = "下一页";

            btnLast.Text = "最后页";

            GridView1.DataBind();

            ShowPageChangedStatus();

        }

       private void ShowPageChangedStatus()

        {

            lblCurrentIndex.Text = "第" + (GridView1.PageIndex + 1).ToString() + "页";

            lblPageCount.Text = "总共 " + GridView1.PageCount.ToString() + " 页";

        }

        public void PagerButtonClick(object sender, EventArgs e)

        {

            string arg = ((LinkButton)sender).CommandArgument.ToString();

            switch (arg)

            {

                case "next":

                    if (GridView1.PageIndex < (GridView1.PageCount - 1))

                    {

                        GridView1.PageIndex += 1;

                    }

                    break;

                case "prev":

                    if (GridView1.PageIndex > 0)

                    {

                        GridView1.PageIndex -= 1;

                    }

                    break;

                case "last":

                    GridView1.PageIndex = (GridView1.PageCount - 1);

                    break;

                default:

                    GridView1.PageIndex = System.Convert.ToInt32(arg);

                    break;

            }

            GridView1.DataBind();

            ShowPageChangedStatus();

        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

        {

            int startIndex;

            startIndex = GridView1.PageIndex * GridView1.PageSize;

            GridView1.PageIndex = e.NewPageIndex;

            GridView1.DataBind();

            ShowPageChangedStatus();

        }

     


      <asp:label id="lblPageCount" runat="server"></asp:label>&nbsp;

      <asp:label id="lblCurrentIndex" runat="server"></asp:label>

      <asp:linkbutton id="btnFirst" onclick="PagerButtonClick" runat="server"

       Font-size="8pt" ForeColor="navy" CommandArgument="0"></asp:linkbutton>&nbsp;

      <asp:linkbutton id="btnPrev" onclick="PagerButtonClick" runat="server"

       Font-size="8pt" ForeColor="navy" CommandArgument="prev"></asp:linkbutton>&nbsp;

      <asp:linkbutton id="btnNext" onclick="PagerButtonClick" runat="server"

       Font-size="8pt" ForeColor="navy" CommandArgument="next"></asp:linkbutton>&nbsp;

      <asp:linkbutton id="btnLast" onclick="PagerButtonClick" runat="server"

       Font-size="8pt" ForeColor="navy" CommandArgument="last"></asp:linkbutton>

  • 相关阅读:
    [翻译] .NET 官宣跨平台 UI 框架 MAUI
    手写一个简易的多周期 MIPS CPU
    介绍一个基于 .NET 的船新 PHP SDK + Runtime: PeachPie
    C# 9 新特性:代码生成器、编译时反射
    .NET 5 中的正则引擎性能改进(翻译)
    你所不知道的 C# 中的细节
    拿 C# 搞函数式编程
    从未来看 C#
    直接使用汇编编写 .NET Standard 库
    用 F# 手写 TypeScript 转 C# 类型绑定生成器
  • 原文地址:https://www.cnblogs.com/tonybinlj/p/1448504.html
Copyright © 2020-2023  润新知