AspNetPager使用方法

先下载4.3版,然后安装

问题:

1.在vs.net2005中,该控件并不能自动添加到工具面板中,需要手动添加项,选定AspNetPager.dll,即可

2.在codeBehind的cs文件中,要using Wuqi.Webdiyer;

3.写好ChangePage事件后,要与aspnetpager控件相关联

以下是一段示例代码:

前台default.aspx

 


 <%...@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"

Inherits="test_Default" StylesheetTheme="default" %>
<%...@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DataList ID="DataList1" runat="server">
            <ItemTemplate>
                ProductName:
                <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Eval("ProductName") %

>'>
                </asp:Label><br />
                <br />
            </ItemTemplate>
        </asp:DataList>
        <webdiyer:aspnetpager id="pager1" runat="server"

onpagechanged="ChangePage"></webdiyer:aspnetpager>   
    </div>
    </form>
</body>
</html>
 

后置代码:default.aspx.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 cpp114.tools.oledb;
using System.Data.OleDb;
using Wuqi.Webdiyer;

public partial class test_Default : System.Web.UI.Page
...{
    protected OleDbConnection conn = new OleDbConnection();
    protected OleDbCommand cmd = new OleDbCommand();

    protected void Page_Load(object sender, EventArgs e)
    ...{
        if (!IsPostBack) ...{
            initdb();
            conn.Open();
            cmd.CommandText = "select count(*) from t_product";
            pager1.RecordCount = (int)cmd.ExecuteScalar();
            conn.Close();
            BindData();
                      
        }

    }
 
 //初始化连接对象
    protected void initdb()...{
        conn.ConnectionString = oledbtool.myConnStr + Server.MapPath(oledbtool.mydbName);
        cmd.Connection = conn;       
    }

 //数据绑定
    protected void BindData() ...{
        initdb();
        OleDbDataAdapter sda = new OleDbDataAdapter("select * from t_product",conn);      
        DataSet ds = new DataSet();
        //sda.Fill(ds, 10, 10, "temptbl");
        sda.Fill(ds, pager1.PageSize * (pager1.CurrentPageIndex - 1), pager1.PageSize, "temptbl");
        DataList1.DataSource = ds.Tables["temptbl"];
        DataList1.DataBind();
    }

 //翻页事件
    protected void ChangePage(object src, PageChangedEventArgs e)
    ...{
        pager1.CurrentPageIndex = e.NewPageIndex;
        BindData();
    }   

}

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CutPage.WebForm1" %> <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table width="100%" border="1" cellspacing="0" cellpadding="4" style="border-collapse: collapse"> <tr style="background-color: #CCCCFF"> <th style="width: 10%">激活码</th> <th style="width: 5%">代理商ID</th> <th style="width: 5%">员工ID</th> <th style="width: 5%">激活数量</th> <th style="width: 10%">开始时间</th> <th style="width: 10%">结束时间</th> <th style="width: 20%">公司名称</th> <th style="width: 20%">公司地址</th> <th style="width: 15%">联系电话</th> </tr> </HeaderTemplate> <ItemTemplate> <tr style="background-color: #FAF3DC"> <td><%#DataBinder.Eval(Container.DataItem,"Activation")%></td> <td><%#DataBinder.Eval(Container.DataItem, "DealerId")%></td> <td><%#DataBinder.Eval(Container.DataItem, "UserId")%></td> <td><%#DataBinder.Eval(Container.DataItem, "Quantity")%></td> <td><%#DataBinder.Eval(Container.DataItem, "StartTime")%></td> <td><%#DataBinder.Eval(Container.DataItem, "EndTime")%></td> <td><%#DataBinder.Eval(Container.DataItem, "CompanyName")%></td> <td><%#DataBinder.Eval(Container.DataItem, "CompanyAddress")%></td> <td><%#DataBinder.Eval(Container.DataItem, "CompanyContact")%></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <webdiyer:aspnetpager id="AspNetPager1" runat="server" onpagechanged="AspNetPager1_PageChanged" currentpagebuttonposition="Center" custominfohtml="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条" firstpagetext="首页" lastpagetext="尾页" layouttype="Table" nextpagetext="下一页" pageindexboxtype="DropDownList" pagingbuttonlayouttype="Span" prevpagetext="上一页" showcustominfosection="Left" submitbuttontext="Go" textafterpageindexbox="页" textbeforepageindexbox="转到"> </webdiyer:aspnetpager> </form> </body> </html>
这个分页控件名为AspNetPager控件,是Asp.net上使用率最高的分页控件,想怎么分就怎么分.附带'超详细代码注释",好用请给评论. 基本步骤: 1.拖拽控件(存放到到Bin目录下,再拖入工具箱) 2.粘贴复制(已放出实例源码) 3.修改Sql语句,即可使用. 特性如下: 强大的各种属性,附带多种CSS,可自定义CSS,想怎么分就怎么分页! 上下页,1234分页,首尾分页,页面跳转,等等,统统一步搞定. 实例代码(包内也有): ___________________________________________________________________ Default.aspx页面↓↓ ___________________________________________________________________ <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!--分页控件命名--> <%@ 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:DataList ID="DataList1" runat="server"> <ItemTemplate> <%# Eval("ID") %> </ItemTemplate> </asp:DataList> <!--分页控件开始--> <webdiyer:AspNetPager ID="Pager1" runat="server" PageSize="8" CssClass="anpager" OnPageChanged="AspNetPager1_PageChanged" FirstPageText="首页 |" LastPageText="| 尾页" NextPageText="下一页" PrevPageText="上一页" ShowPageIndexBox="Always" AlwaysShow="True" Font-Size="13px"> </webdiyer:AspNetPager> <!--分页控件结束--> </div> </form> </body> </html> ____________________________________________________________ Default.aspx.cs页面代码↓↓ ____________________________________________________________ using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; //引用命名空间 using System.Data; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { string connstring = "server=baiyi-js\\SQL2005;uid=sa;pwd=123456;database=xcbaiyi";//修改数据库连接字符串(必须改) protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection conn = null; try { conn = new SqlConnection(connstring); conn.Open(); SqlCommand Count = new SqlCommand(); Count.Connection = conn; Count.CommandText = "select count(*) from tuiguang_2"; //Sql查询语句(必修改) Pager1.RecordCount = (int)Count.ExecuteScalar(); //"Pager1"为分页控件ID.在工具箱拖拽添加控件,同时会在aspx页面顶部添加控件命名控件(无需修改) BindData(); } finally { conn.Close(); } } } //绑定数据-2_只修改Sql语句即可 public void BindData() { SqlConnection conn = new SqlConnection(connstring); string sql = "select * from tuiguang_2";//Sql查询语句(必修改) SqlDataAdapter da = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); da.Fill(ds, Pager1.PageSize * (Pager1.CurrentPageIndex - 1), Pager1.PageSize, "temptbl"); DataTable dt = ds.Tables["temptbl"]; DataList1.DataSource = dt; DataList1.DataBind(); } //控件事件-每次重新绑定_不需修改 protected void AspNetPager1_PageChanged(object src, EventArgs e) { BindData(); } }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值