栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

asp.net分页控件使用详解

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

asp.net分页控件使用详解

一、说明

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属性是用于设置每页显示的数量

    4、后台代码绑定

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

    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)

     以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持考高分网!

    转载请注明:文章转载自 www.mshxw.com
    本文地址:https://www.mshxw.com/it/55870.html
    我们一直用心在做
    关于我们 文章归档 网站地图 联系我们

    版权所有 (c)2021-2022 MSHXW.COM

    ICP备案号:晋ICP备2021003244-6号