快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

如何理解asp.net的分页控件-创新互联

这篇文章给大家介绍如何理解asp.net的分页控件,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

成都创新互联公司10多年企业网站设计服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,企业网站设计及推广,对成都宴会酒店设计等多个行业拥有多年的网站推广经验的网站建设公司。

一、说明

AspNetPager.dll这个分页控件主要用于asp.net webform网站,现将整理代码如下

二、代码

1、首先在测试页面Default.aspx页面添加引用

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

2、写一个Repeater列表控件用于显示数据


  
    
  •       <%# Eval("time") %>       "><%# Access.GetStringNum( Eval("name").ToString(),15) %>     
  •   

    3、添加

    
    

    PageSize属性是用于设置每页显示的数量

    如何理解asp.net的分页控件

    如何理解asp.net的分页控件

    4、后台代码绑定

    //测试数据源
    private void ShowNews() {   String strSql = String.Format("select * from News order by time asc");   DataTable dtbl = Access.ExecuteDataTable(strSql, null);   this.rptNews.DataSource = Access.GetPageDataSource(AspNetPager1, AspNetPager1.CurrentPageIndex - 1, dtbl);   this.rptNews.DataBind(); }

    Access是测试数据库访问类,在最后的Demo中提供给大家

    5、分页控件点击页码事件

    //分页
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
      this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
      ShowNews();
    } 


    最后奉上整页代码:

    Default.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
    <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
    
    
    
     
     asp.net分页控件
     
     
     .aboutcontentnr{width:100%; height:auto; }
     
    
    
     
     
                     
  •       <%# Eval("time") %>"><%# Access.GetStringNum( Eval("name").ToString(),15) %>
  •     
                        
     
     

    Default.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    public partial class Default : System.Web.UI.Page
    {
     protected void Page_Load(object sender, EventArgs e)
     {
      if (!IsPostBack)
      {
       ShowNews();
      }
     }
     //测试数据源
     private void ShowNews()
     {
      String strSql = String.Format("select * from News order by time asc");
      DataTable dtbl = Access.ExecuteDataTable(strSql, null);
      this.rptNews.DataSource = Access.GetPageDataSource(AspNetPager1, AspNetPager1.CurrentPageIndex - 1, dtbl);
      this.rptNews.DataBind();
     }
     //分页点击页码事件
     protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
     {
      this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
      ShowNews();
     }
    }

    三、Demo

    AspNetPager(dll)

    AspNetPage(Demo)

    关于如何理解asp.net的分页控件就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


    标题名称:如何理解asp.net的分页控件-创新互联
    标题网址:http://6mz.cn/article/eipgc.html

    其他资讯