惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
The Last Watchdog
The Last Watchdog
T
Tenable Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
V
Vulnerabilities – Threatpost
F
Fortinet All Blogs
Microsoft Security Blog
Microsoft Security Blog
A
Arctic Wolf
云风的 BLOG
云风的 BLOG
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
GbyAI
GbyAI
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
MyScale Blog
MyScale Blog
B
Blog
Spread Privacy
Spread Privacy
S
Schneier on Security
Project Zero
Project Zero
L
LINUX DO - 热门话题
M
MIT News - Artificial intelligence
F
Full Disclosure
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
Cyberwarzone
Cyberwarzone
AWS News Blog
AWS News Blog
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
Security Latest
Security Latest
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tailwind CSS Blog
K
Kaspersky official blog
Recent Announcements
Recent Announcements
NISL@THU
NISL@THU
Cisco Talos Blog
Cisco Talos Blog
S
Securelist
P
Privacy & Cybersecurity Law Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
The Exploit Database - CXSecurity.com
V
Visual Studio Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Webroot Blog
Webroot Blog

博客园 - Angelo Dell'inferno

[ASP.NET] 基于.Net Remoting 的网站访问监控模块 [转]Run a Http Response Filter together with an Ajax Update Panel [ASP.NET] HyperLink + Image 实现动态图片链接 [ASP.NET] (转)地址栏参数的判断 [ASP.NET] 实现Label自动换行 [ASP.NET] 验证码生成 [ASP.NET] 实现客户端浏览服务端目录的页面 [ASP.NET]Treeview 控件显示服务端目录文件夹及文件 [C#] GridView导出到Excel [C#] 获取两个时间点的时间间隔 [SQL Server][转]数据库并发控制——活锁&死锁 [JavaScript] 防止页面被嵌入Iframe [SQL Server] 存储过程事务 [SQL Server] T-SQL 连接数据库方法 [C#] 杀Excel进程 [C#] 将DataSet内容导入到Excel (矩阵区域导出) [ASP.NET] 服务器端下载文件实现 [Oracle] 日期相关操作 [ORACLE] 函数大全
[ASP.NET] (原创)自定义GridView分页
Angelo Dell'inferno · 2007-12-24 · via 博客园 - Angelo Dell'inferno

1. aspx页面端代码:

<div class="gv-footer">
          <asp:LinkButton ID="btFirstPage" runat="server" CommandArgument="first" OnClick ="PagerButton_Click">首页</asp:LinkButton>
        <asp:LinkButton ID="btPrevPage" runat="server" CommandArgument="prev" OnClick ="PagerButton_Click">上一页</asp:LinkButton>
        <asp:LinkButton ID="btNextPage" runat="server" CommandArgument="next" OnClick ="PagerButton_Click">下一页</asp:LinkButton>
        <asp:LinkButton ID="btLastPage" runat="server" CommandArgument="last" OnClick ="PagerButton_Click">尾页</asp:LinkButton>
        页码:
        <asp:Label ID="lbCurrentPage" runat="server" ForeColor="Blue"></asp:Label>
        /
        <asp:Label ID="lbTotalPage" runat="server"></asp:Label>
        <asp:DropDownList ID="ddlPageSelect" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlPageSelect_SelectedIndexChanged"> </asp:DropDownList>
      </div>

2. aspx.cs端代码:

#region GridView分页
   /// <summary>
   /// 页面选择操作
   /// </summary>
   /// <param name="sender"></param>
   /// <param name="e"></param>
   protected void PagerButton_Click(object sender, EventArgs e)
   {
       int pageIndex = gvSailingList.PageIndex;

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

       switch (arg)
       {
           case "prev":

               if (pageIndex > 0)
               {
                   pageIndex -= 1;
               }
               break;
           case "next":
               if (pageIndex < gvSailingList.PageCount)
               {
                   pageIndex += 1;
               }
               break;
           case "last":
               pageIndex = gvSailingList.PageCount - 1;
               break;
           default:
               pageIndex = 0;
               break;
       }

       gvSailingList.PageIndex = pageIndex;
       BindSailing();
   }

   /// <summary>
   /// 页码选择下拉条绑定
   /// </summary>
   protected void PageBind()
   {
       ddlPageSelect.Items.Clear();
       for (int i = 0; i < gvSailingList.PageCount; i++)
       {
           ddlPageSelect.Items.Insert(i, Convert.ToString(i + 1));
       }
       if (gvSailingList.PageCount > 0)
       {
           SetPageButton(true);
           ddlPageSelect.SelectedIndex = gvSailingList.PageIndex;
       }
       else
       {
           SetPageButton(false);
           ddlPageSelect.SelectedIndex = -1;
       }
   }

   /// <summary>
   /// 设置页码按钮的可见性
   /// </summary>
   protected void SetPageButton(bool ViewEnable)
   {
       //无数据时按钮变灰
       if (ViewEnable == false)
       {
           btFirstPage.Enabled = false;
           btLastPage.Enabled = false;
           btNextPage.Enabled = false;
           btPrevPage.Enabled = false;
           ddlPageSelect.Enabled = false;
       }
       //有数据时按钮显示
       else if (ViewEnable == true)
       {
           btFirstPage.Enabled = true;
           btLastPage.Enabled = true;
           btNextPage.Enabled = true;
           btPrevPage.Enabled = true;
           ddlPageSelect.Enabled = true;
       }
   }

   /// <summary>
   /// 页码选择栏 显示控制
   /// </summary>
   protected void PageDisplay()
   {
       //页码显示
       if (gvSailingList.PageCount > 0)
       {
           lbCurrentPage.Text = Convert.ToString(gvSailingList.PageIndex + 1);
       }
       else
       {
           lbCurrentPage.Text = Convert.ToString(gvSailingList.PageIndex);
       }
       lbTotalPage.Text = gvSailingList.PageCount.ToString();
   }

   /// <summary>
   /// 跳转到指定页
   /// </summary>
   /// <param name="sender"></param>
   /// <param name="e"></param>
   protected void ddlPageSelect_SelectedIndexChanged(object sender, EventArgs e)
   {
       gvSailingList.PageIndex = ddlPageSelect.SelectedIndex;
       BindSailing();
   }
   #endregion

#region 私有方法 
   protected void BindSailing()
   {
        gvSailingList.DataSource = dt.DefaultView;
        gvSailingList.DataBind();

        PageBind();
        PageDisplay();
   }

#endregion