关于用户控件分页 用户控件有:首页,上一页,下一页,末页,跳转只包含以上控件在页面上与Repeater实现分页显示效果, 代码不知道如何写? 希望提供代码或地址,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 AspnetPager这个应该符合你要求 AspNetPager实例加入引用将AspNetPager控件引入到项目中,即在aspx页面里添加引用,把AspNetPager的dll文件加到Bin文件夹目录下using System.Data.SqlClient;using Wuqi.Webdiyer;<%@ 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> <link href="StyleSheet.css" rel="stylesheet" type="text/css" /></head><body> <form id="form1" runat="server"> <div> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate><ul></HeaderTemplate> <ItemTemplate> <li><%#"客户ID: "+Eval("customerid") %> <%#" 公司名称: "+Eval("companyname") %> <%#" 联系地址: "+Eval("address") %></li> </ItemTemplate> <FooterTemplate></ul></FooterTemplate> </asp:Repeater> <br /> <webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="" LastPageText="" NextPageText="下一页" OnPageChanging="AspNetPager1_PageChanging" CssClass="pages" CurrentPageButtonClass="cpb" PrevPageText="上一页"> </webdiyer:AspNetPager> </div> </form></body></html>using System;using System.Data;using System.Configuration;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;using Wuqi.Webdiyer;public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bindsql(); } } private void bindsql() { SqlConnection con = new SqlConnection("Data Source=20090731-5465;Initial Catalog=Northwind;Integrated Security=True"); con.Open(); SqlDataAdapter sqlda = new SqlDataAdapter("select * from customers", con); DataSet ds = new DataSet(); sqlda.Fill(ds); PagedDataSource pdsList = new PagedDataSource(); pdsList.DataSource = ds.Tables[0].DefaultView; pdsList.AllowPaging = true;//数据源允许分页 pdsList.PageSize = this.AspNetPager1.PageSize;//取控件的分页大小 pdsList.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;//显示当前页 //设置控件 this.AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;//记录总数 this.AspNetPager1.PageSize = 10; this.Repeater1.DataSource = pdsList; this.Repeater1.DataBind(); } protected void AspNetPager1_PageChanging(object src, PageChangingEventArgs e) { AspNetPager1.CurrentPageIndex = e.NewPageIndex; bindsql(); }}CSSbody {}.pages { color: #999; }.pages a, .pages .cpb { text-decoration:none;float: left; padding: 0 5px; border: 1px solid #ddd;background: #ffff;margin:0 2px; font-size:11px; color:#000;}.pages a:hover { background-color: #E61636; color:#fff;border:1px solid #E61636; text-decoration:none;}.pages .cpb { font-weight: bold; color: #fff; background: #E61636; border:1px solid #E61636;} http://www.cnblogs.com/chenping-987123/archive/2011/02/14/1954640.html自己写的无刷新分页。 那用这种吧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 a9 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { DataListBind();//注意不能写在 if (!IsPostBack)里那样回传时就不会调用这个函数了,点击就不管作用了 } public void DataListBind() { PagedDataSource objpage = new PagedDataSource(); Book dlBook = new Book(); objpage.DataSource = dlBook.dsBook("select * from books").Tables[0].DefaultView; objpage.AllowPaging = true; objpage.PageSize = 2; int curpage; if (Request.QueryString["Page"] != null) { curpage = Convert.ToInt32(Request.QueryString["Page"]); } else { curpage = 1; } objpage.CurrentPageIndex = curpage - 1; if (objpage.IsFirstPage && objpage.IsLastPage) { this.LBfirst.Enabled = false; this.LBpre.Enabled = false; this.LBnext.Enabled = false; this.LBlast.Enabled = false; } else { if (objpage.IsFirstPage && !objpage.IsLastPage) { this.LBfirst.Enabled = false; this.LBpre.Enabled = false; this.LBnext.Enabled = true; this.LBlast.Enabled = true; this.LBnext.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage + 1); this.LBlast.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(objpage.PageCount); } else { if (objpage.IsLastPage && !objpage.IsFirstPage) { this.LBfirst.Enabled = true; this.LBpre.Enabled = true; this.LBnext.Enabled = false; this.LBlast.Enabled = false; this.LBfirst.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + 1; this.LBpre.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage - 1); } else { this.LBfirst.Enabled = true; this.LBpre.Enabled = true; this.LBnext.Enabled = true; this.LBlast.Enabled = true; this.LBfirst.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + 1; this.LBpre.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage - 1); this.LBnext.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage + 1); this.LBlast.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(objpage.PageCount); } } } this.Repeater1.DataSource = objpage; this.Repeater1.DataBind(); }}<%@ Page Language="C#" AutoEventWireup="true" CodeFile="a9.aspx.cs" Inherits="a9" %><!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:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <%# Eval("BookName") %> </ItemTemplate> </asp:Repeater> </div> <asp:LinkButton ID="LBfirst" runat="server" CommandArgument="first">首页</asp:LinkButton> <asp:LinkButton ID="LBpre" runat="server">上一页</asp:LinkButton> <asp:LinkButton ID="LBnext" runat="server">下一页</asp:LinkButton> <asp:LinkButton ID="LBlast" runat="server">尾页</asp:LinkButton> </form></body></html>本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xinruzhishui119/archive/2009/09/19/4569353.aspx http://blog.csdn.net/xinruzhishui119/archive/2009/09/19/4569353.aspx 求一简单正则表达式 一个查询语句 SELECT问题 关于asp.net中的登录系统 我做了个网站,为什么访问很慢 ASP.NET页面传值问题 如何在asp.net代码中执行打开一个窗口的动作 请c#+asp.net高手进来看看 写ServerControl时,什么样的属性应该保存到ViewState? log4net 日志丢失问题 vs2008怎么创建空白mvc程序呀? 【求助】关于ASP.NET二进流图片同时显示多张的问题
实例加入引用将AspNetPager控件引入到项目中,即在aspx页面里添加引用,把AspNetPager的dll文件加到Bin文件夹目录下
using System.Data.SqlClient;
using Wuqi.Webdiyer;<%@ 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>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<ItemTemplate>
<li><%#"客户ID: "+Eval("customerid") %> <%#" 公司名称: "+Eval("companyname") %> <%#" 联系地址: "+Eval("address") %></li>
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
<br />
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="" LastPageText=""
NextPageText="下一页" OnPageChanging="AspNetPager1_PageChanging" CssClass="pages" CurrentPageButtonClass="cpb" PrevPageText="上一页">
</webdiyer:AspNetPager>
</div>
</form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
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;
using Wuqi.Webdiyer;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindsql();
}
}
private void bindsql()
{
SqlConnection con = new SqlConnection("Data Source=20090731-5465;Initial Catalog=Northwind;Integrated Security=True");
con.Open();
SqlDataAdapter sqlda = new SqlDataAdapter("select * from customers", con);
DataSet ds = new DataSet();
sqlda.Fill(ds);
PagedDataSource pdsList = new PagedDataSource();
pdsList.DataSource = ds.Tables[0].DefaultView;
pdsList.AllowPaging = true;//数据源允许分页
pdsList.PageSize = this.AspNetPager1.PageSize;//取控件的分页大小
pdsList.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;//显示当前页
//设置控件
this.AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;//记录总数
this.AspNetPager1.PageSize = 10;
this.Repeater1.DataSource = pdsList;
this.Repeater1.DataBind(); }
protected void AspNetPager1_PageChanging(object src, PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
bindsql();
}
}CSS
body {
}
.pages { color: #999; }
.pages a, .pages .cpb { text-decoration:none;float: left; padding: 0 5px; border: 1px solid #ddd;background: #ffff;margin:0 2px; font-size:11px; color:#000;}
.pages a:hover { background-color: #E61636; color:#fff;border:1px solid #E61636; text-decoration:none;}
.pages .cpb { font-weight: bold; color: #fff; background: #E61636; border:1px solid #E61636;}
自己写的无刷新分页。
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 a9 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataListBind();//注意不能写在 if (!IsPostBack)里那样回传时就不会调用这个函数了,点击就不管作用了
}
public void DataListBind()
{
PagedDataSource objpage = new PagedDataSource();
Book dlBook = new Book();
objpage.DataSource = dlBook.dsBook("select * from books").Tables[0].DefaultView;
objpage.AllowPaging = true;
objpage.PageSize = 2;
int curpage;
if (Request.QueryString["Page"] != null)
{
curpage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
curpage = 1;
}
objpage.CurrentPageIndex = curpage - 1;
if (objpage.IsFirstPage && objpage.IsLastPage)
{
this.LBfirst.Enabled = false;
this.LBpre.Enabled = false;
this.LBnext.Enabled = false;
this.LBlast.Enabled = false;
}
else
{
if (objpage.IsFirstPage && !objpage.IsLastPage)
{
this.LBfirst.Enabled = false;
this.LBpre.Enabled = false;
this.LBnext.Enabled = true;
this.LBlast.Enabled = true;
this.LBnext.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage + 1);
this.LBlast.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(objpage.PageCount);
}
else
{
if (objpage.IsLastPage && !objpage.IsFirstPage)
{
this.LBfirst.Enabled = true;
this.LBpre.Enabled = true;
this.LBnext.Enabled = false;
this.LBlast.Enabled = false;
this.LBfirst.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + 1;
this.LBpre.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage - 1);
}
else
{
this.LBfirst.Enabled = true;
this.LBpre.Enabled = true;
this.LBnext.Enabled = true;
this.LBlast.Enabled = true;
this.LBfirst.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + 1;
this.LBpre.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage - 1);
this.LBnext.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage + 1);
this.LBlast.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(objpage.PageCount);
}
}
}
this.Repeater1.DataSource = objpage;
this.Repeater1.DataBind();
}
}<%@ Page Language="C#" AutoEventWireup="true" CodeFile="a9.aspx.cs" Inherits="a9" %><!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:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%# Eval("BookName") %>
</ItemTemplate>
</asp:Repeater>
</div>
<asp:LinkButton ID="LBfirst" runat="server" CommandArgument="first">首页</asp:LinkButton>
<asp:LinkButton ID="LBpre" runat="server">上一页</asp:LinkButton>
<asp:LinkButton ID="LBnext" runat="server">下一页</asp:LinkButton>
<asp:LinkButton ID="LBlast" runat="server">尾页</asp:LinkButton>
</form>
</body>
</html>本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xinruzhishui119/archive/2009/09/19/4569353.aspx