Aspnetpage分页

分页有好多种,在以前写了存储过程,也用过pagedatasource,也自己写过代码,听好友说了aspnetpage,于是就试了试:

后台.cs:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class MMM : System.Web.UI.Page
{
    DataBase db = new DataBase();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
            string strsql = "SELECT count([A_id]) FROM [Agent]";
            SqlCommand myCommand = new SqlCommand(strsql, myConnection);
            myCommand.CommandType = CommandType.Text;
            SqlDataAdapter myda = new SqlDataAdapter();
            myda.SelectCommand = myCommand;
            DataSet ds = new DataSet();
            myda.Fill(ds, "news");
            this.AspNetPager1.RecordCount = System.Convert.ToInt32(ds.Tables[0].Rows[0][0]);  
            BindData();  
        }  

           
        }
     void BindData()  
    {  
       
        SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());  
        string strsql = "SELECT * FROM [Agent]";  
        SqlCommand myCommand = new SqlCommand(strsql, myConnection);  
        myCommand.CommandType = CommandType.Text;  
        SqlDataAdapter myda = new SqlDataAdapter();  
        myda.SelectCommand = myCommand;  
        DataSet ds = new DataSet();  
        myda.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "news");  
        this.GridView1.DataSource = ds.Tables["news"];
        this.GridView1.DataBind();  
        //动态设置用户自定义文本内容   
        AspNetPager1.CustomInfoHTML = "记录总数:<font color=/"blue/"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";  
        AspNetPager1.CustomInfoHTML += " 总页数:<font color=/"blue/"><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";  
        AspNetPager1.CustomInfoHTML += " 当前页:<font color=/"red/"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";  
 

    }  
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)  
    {  
       
        BindData();   
 
    }  
}  
 
前台:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MMM.aspx.cs" Inherits="MMM" %>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" Height="118px" Width="289px">
        </asp:GridView>
       <Webdiyer:AspNetPager id="AspNetPager1" AlwaysShow="true"
           runat="server"
           PageSize="8"
           NumericButtonCount="8"
           ShowCustomInfoSection="left"
           PagingButtonSpacing="0"
           ShowInputBox="always"
           CssClass="mypager"
           HorizontalAlign="right"
           SubmitButtonText="转到"
           NumericButtonTextFormatString="[{0}]" OnPageChanged="AspNetPager1_PageChanged" Width="168px"/>
    </div>
    </form>
</body>
</html>
当然要引用AspNetPager.dll了!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值