求一个asp.net分页的例子!
分页样式要是这样:page:123456789...>>如果点了>>就换成这样:page:<<...10111213141516171819...>>其它的:首页上一页下...
分页样式要是这样:
page: 1 2 3 4 5 6 7 8 9 ...>>
如果点了>>就换成这样:
page:<< ... 10 11 12 13 14 15 16 17 18 19 ...>>
其它的:首页 上一页 下一页 尾页 这样的不要!这样的我已经会了!
写出分页过程参考下就可以了!数据源方面可以忽略!
回复1楼的:我是在边开发东西,边在学东西,所以需要自己做出来才舒服!要自己了解下!
回复2楼的:都说不要这样的:"首页 上一页 下一页 尾页 "分页样式了!这样的一点用户体验都没有!如果有几百页,要打开的页码在中间点,那头都点晕掉都找不到需要的那页!另外你那代码好象是网上粘的吧?我好象见过! 展开
page: 1 2 3 4 5 6 7 8 9 ...>>
如果点了>>就换成这样:
page:<< ... 10 11 12 13 14 15 16 17 18 19 ...>>
其它的:首页 上一页 下一页 尾页 这样的不要!这样的我已经会了!
写出分页过程参考下就可以了!数据源方面可以忽略!
回复1楼的:我是在边开发东西,边在学东西,所以需要自己做出来才舒服!要自己了解下!
回复2楼的:都说不要这样的:"首页 上一页 下一页 尾页 "分页样式了!这样的一点用户体验都没有!如果有几百页,要打开的页码在中间点,那头都点晕掉都找不到需要的那页!另外你那代码好象是网上粘的吧?我好象见过! 展开
展开全部
Repeater和DataList控件提供了一个快速、灵活的表现数据的方式,但是,它们没有内建的分页功能;DataGrid控件提供了内建的分页功能,但它的结构比较复杂。下面就用PagedDataSource类实现Repeater和DataList的分页。 PagedDataSource封装了DataGrid的分页属性,我们可以象DataGrid那样进行分页。代码如下:
C#版本
<%@ Page Language="C#" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.OleDb" %>
<script language="C#" runat="server">
public void Page_Load(Object src,EventArgs e) {
OleDbConnection objConn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" +
Server.MapPath("../<a href="http://dev.21tx.com/web/asp/" target="_blank">ASP</a>x<a href="http://dev.21tx.com/web/" target="_blank">Web</a>.mdb"));
OleDbDataAdapter objCommand=new OleDbDataAdapter("select * from Document",objConn);
DataSet ds=new DataSet();
objCommand.Fill(ds);
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds.Tables[0].DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 5;
int CurPage;
if (Request.QueryString["Page"] != null)
CurPage=Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage=1;
objPds.CurrentPageIndex = CurPage-1;
lblCurrentPage.Text = "当前页:" + CurPage.ToString();
if (!objPds.IsFirstPage)
lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage-1);
if (!objPds.IsLastPage)
lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage+1);
Repeater1.DataSource=objPds;
Repeater1.DataBind();
}
</script>
<html>
<head>
<title>Repeater控件分页的例子</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
P,TD,DIV,SPAN {font-size:9pt}
</style>
</head>
<body>
<form name="form1" method="POST" runat="server">
<div style="padding:5px;background-color:#dedede">
<asp:label ID="lblCurrentPage" runat="server"></asp:label></td>
<td> <asp:HyperLink id="lnkPrev" runat="server">上一页</asp:HyperLink>
<asp:HyperLink id="lnkNext" runat="server">下一页</asp:HyperLink>
</div>
<hr size="1" color="#000099"/>
<asp:Repeater ID="Repeater1" runat="server">
<Itemtemplate>
<div style="padding:5px;background-color:#dedede">
<%# DataBinder.Eval(Container.DataItem, "Title") %>
</div>
</Itemtemplate>
</asp:Repeater>
</form>
</body>
</html>
VB.NET版本
<%@ Page Language="VB" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
Public Sub Page_Load(ByVal src As Object, ByVal e As EventArgs)
Dim objConn As OleDbConnection = New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("../aspxWeb.mdb"))
Dim objCommand As OleDbDataAdapter = New OleDbDataAdapter ("select * from Document", objConn)
Dim ds As DataSet = New DataSet ()
objCommand.Fill(ds)
Dim objPds As PagedDataSource = New PagedDataSource ()
objPds.DataSource = ds.Tables(0).DefaultView
objPds.AllowPaging = True
objPds.PageSize = 5
Dim CurPage As Integer
If Not (Request.QueryString("Page") Is Nothing) Then
CurPage = Convert.ToInt32(Request.QueryString("Page"))
Else
CurPage = 1
End If
objPds.CurrentPageIndex = CurPage - 1
lblCurrentPage.Text = "当前页:" + CurPage.ToString()
If Not objPds.IsFirstPage Then
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1)
End If
If Not objPds.IsLastPage Then
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1)
End If
Repeater1.DataSource = objPds
Repeater1.DataBind()
End Sub
</script>
<html>
<head>
<title>Repeater控件分页的例子</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
P,TD,DIV,SPAN {font-size:9pt}
</style>
</head>
<body>
<form name="form1" method="POST" runat="server">
<div style="padding:5px;background-color:#dedede">
<asp:label ID="lblCurrentPage" runat="server"></asp:label></td>
<td> <asp:HyperLink id="lnkPrev" runat="server">上一页</asp:HyperLink>
<asp:HyperLink id="lnkNext" runat="server">下一页</asp:HyperLink>
</div>
<hr size="1" color="#000099"/>
<asp:Repeater ID="Repeater1" runat="server">
<Itemtemplate>
<div style="padding:5px;background-color:#dedede">
<%# DataBinder.Eval(Container.DataItem, "Title") %>
</div>
</Itemtemplate>
</asp:Repeater>
</form>
</body>
</html>
<%''本程序文件名为:Pages.ASP%>
<%''包含ADO常量表文件adoVBs.inc,可从"\Program Files\Common Files\System\ADO"目录下拷贝%>
<!--#Include File="adovbs.inc"
<%''*建立数据库连接,这里是Oracle8.05数据库
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Provider=msdaora.1;Data Source=YourSrcName;User ID=YourUserID;Password=YourPassword;"
Set rs=Server.CreateObject("ADODB.Recordset") ''创建Recordset对象
rs.CursorLocation=adUseClient ''设定记录集指针属性
''*设定一页内的记录总数,可根据需要进行调整
rs.PageSize=10
''*设置查询语句
StrSQL="Select ID,姓名,住址,电话 from 通讯录 Order
C#版本
<%@ Page Language="C#" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.OleDb" %>
<script language="C#" runat="server">
public void Page_Load(Object src,EventArgs e) {
OleDbConnection objConn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" +
Server.MapPath("../<a href="http://dev.21tx.com/web/asp/" target="_blank">ASP</a>x<a href="http://dev.21tx.com/web/" target="_blank">Web</a>.mdb"));
OleDbDataAdapter objCommand=new OleDbDataAdapter("select * from Document",objConn);
DataSet ds=new DataSet();
objCommand.Fill(ds);
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds.Tables[0].DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 5;
int CurPage;
if (Request.QueryString["Page"] != null)
CurPage=Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage=1;
objPds.CurrentPageIndex = CurPage-1;
lblCurrentPage.Text = "当前页:" + CurPage.ToString();
if (!objPds.IsFirstPage)
lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage-1);
if (!objPds.IsLastPage)
lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage+1);
Repeater1.DataSource=objPds;
Repeater1.DataBind();
}
</script>
<html>
<head>
<title>Repeater控件分页的例子</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
P,TD,DIV,SPAN {font-size:9pt}
</style>
</head>
<body>
<form name="form1" method="POST" runat="server">
<div style="padding:5px;background-color:#dedede">
<asp:label ID="lblCurrentPage" runat="server"></asp:label></td>
<td> <asp:HyperLink id="lnkPrev" runat="server">上一页</asp:HyperLink>
<asp:HyperLink id="lnkNext" runat="server">下一页</asp:HyperLink>
</div>
<hr size="1" color="#000099"/>
<asp:Repeater ID="Repeater1" runat="server">
<Itemtemplate>
<div style="padding:5px;background-color:#dedede">
<%# DataBinder.Eval(Container.DataItem, "Title") %>
</div>
</Itemtemplate>
</asp:Repeater>
</form>
</body>
</html>
VB.NET版本
<%@ Page Language="VB" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
Public Sub Page_Load(ByVal src As Object, ByVal e As EventArgs)
Dim objConn As OleDbConnection = New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("../aspxWeb.mdb"))
Dim objCommand As OleDbDataAdapter = New OleDbDataAdapter ("select * from Document", objConn)
Dim ds As DataSet = New DataSet ()
objCommand.Fill(ds)
Dim objPds As PagedDataSource = New PagedDataSource ()
objPds.DataSource = ds.Tables(0).DefaultView
objPds.AllowPaging = True
objPds.PageSize = 5
Dim CurPage As Integer
If Not (Request.QueryString("Page") Is Nothing) Then
CurPage = Convert.ToInt32(Request.QueryString("Page"))
Else
CurPage = 1
End If
objPds.CurrentPageIndex = CurPage - 1
lblCurrentPage.Text = "当前页:" + CurPage.ToString()
If Not objPds.IsFirstPage Then
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1)
End If
If Not objPds.IsLastPage Then
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1)
End If
Repeater1.DataSource = objPds
Repeater1.DataBind()
End Sub
</script>
<html>
<head>
<title>Repeater控件分页的例子</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
P,TD,DIV,SPAN {font-size:9pt}
</style>
</head>
<body>
<form name="form1" method="POST" runat="server">
<div style="padding:5px;background-color:#dedede">
<asp:label ID="lblCurrentPage" runat="server"></asp:label></td>
<td> <asp:HyperLink id="lnkPrev" runat="server">上一页</asp:HyperLink>
<asp:HyperLink id="lnkNext" runat="server">下一页</asp:HyperLink>
</div>
<hr size="1" color="#000099"/>
<asp:Repeater ID="Repeater1" runat="server">
<Itemtemplate>
<div style="padding:5px;background-color:#dedede">
<%# DataBinder.Eval(Container.DataItem, "Title") %>
</div>
</Itemtemplate>
</asp:Repeater>
</form>
</body>
</html>
<%''本程序文件名为:Pages.ASP%>
<%''包含ADO常量表文件adoVBs.inc,可从"\Program Files\Common Files\System\ADO"目录下拷贝%>
<!--#Include File="adovbs.inc"
<%''*建立数据库连接,这里是Oracle8.05数据库
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Provider=msdaora.1;Data Source=YourSrcName;User ID=YourUserID;Password=YourPassword;"
Set rs=Server.CreateObject("ADODB.Recordset") ''创建Recordset对象
rs.CursorLocation=adUseClient ''设定记录集指针属性
''*设定一页内的记录总数,可根据需要进行调整
rs.PageSize=10
''*设置查询语句
StrSQL="Select ID,姓名,住址,电话 from 通讯录 Order
展开全部
用可以用AspNetPager分页控件来完全可以满足你的要求。
你可以在百度上搜索AspNetPager可以找到你想要的。
你可以在百度上搜索AspNetPager可以找到你想要的。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这是一个用户自定义控件,稍加改进就可以实现你的需求,实例:http://www1.cttstar.com:8010/gamenewslist.aspx?id=184
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询