求个高效的repeater分页源代码!
做为参考!
做为参考!
解决方案 »
- [求教]京东商城的购物车
- 引用Interop.Excel.dll,布署服务器时,如何注册组件呢?
- 谁会使用SharePowerDataGrid?
- 我要全屏打开一个窗口,但还要能够显示工具栏,地址栏等,请问该如何做?
- 微软2004teched资料下载地址
- 为什么 ASP.NET 高级编程中的一段代码不能运行?
- 斑竹等高手進來,即時查詢問題,大放分!!!
- VS2005,关于GridView分页与到处Excel的问题
- 使用Ajax后。。GridView某些按钮功能失效!
- 这问题不懂在哪个版块问了,还是来熟悉的地方吧
- iTextSharp的問題,估計問了也是白問,沒人能回答得了
- gridview配置对象数据源时无法找到业务类?
有没有做过“一个没有依靠控件的分页代码,输出的数据也没有依靠控件的分页代码弄过没有?”
我做的效果如下:
ASPX页面就一个: <%=table%>
aspx.cs页面代码:
-----------------------------------------------------
#region 切换图
public string table = "", id="";
private void BindQieHuanTu()
{
con = new SqlConnection(zglh.returnSqlstr());
cmd = con.CreateCommand();
cmd.CommandText = "select * from guanggao where gg_type='首页滚动图片' and gg_if='是' order by gg_sort asc,gg_time desc";
try
{
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
int i = 1;
while (dr.Read())
{
string pic = Convert.ToString(dr["gg_pic"]);
string gg_id = dr["gg_id"].ToString();
//string id = string.Empty;
string pic1 = "admin/guanggao/" + pic;
string pic2 = " <td width=\"278\" height=\"96\" valign=\"top\"> <table width=\"274\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#FFFFFF\"> <tr> <td width=\"97\" align=\"center\" valign=\"middle\"> <a href='" + dr["gg_id"] + "'> <img src=\"" + pic1 + "\" width=\"70\" height=\"60\" border=0 /> </a> </td> <td width=\"177\" align=\"left\" class=\"hg\">英国《每日电讯报》26日报道道 <br />英国女子坦娅·迪克森堪称爱迪 <br />克森堪称爱迪克森堪称爱迪克森 <br />堪称爱迪克森堪... </td> </tr> </table> </td>";
table += pic2;
if (i % 2 == 0)
{
table += " <td width=\"98\" align=\"center\" valign=\"top\"> <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td height=\"65\"> </td> </tr> <tr> <td> <a href='ceshi1.aspx?id=" + id + "," + dr["gg_id"] + "'> <img src=\"images/db.jpg\" width=\"97\" height=\"27\" border=0 /> </a> </td> </tr> </table> </td> </tr> <tr>";
}
else
{
id = gg_id;
}
i++;
}
dr.Close();
con.Close();
}
catch
{
con.Close();
}
}
#endregion
---------------------------------------------------------------------------------------------
请问这种输出数据没有依靠控件,分页也不依靠控件的分页效果怎么做。发出效果代码,谢谢
源码:
http://www.cnblogs.com/xuanfeng/archive/2007/04/08/704366.html2、普通方式
http://www.webasp.net/article/28/27885.htm3、可以使用AspNetPage来分页,使用方便,用存储过程方式调用,效率挺高的
直接下一个AspNetPage控件就行了,是一个开源的.而且使用方法到处都能找到,只有这个最简单
PDS.DataSource =((DataTable)Session["data"]).DefaultView;
PDS.CurrentPageIndex = index;
PDS.AllowPaging = true;
PDS.PageSize = 20;
this.Repeater2.DataSource = PDS;
this.Repeater2.DataBind();就像这里
Pagination.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Pagination.aspx.cs" Inherits="Pagination" %> <!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 align="center">
<asp:Literal ID="paginationResult" runat="server"> </asp:Literal>
<asp:Literal ID="paginationInfo" runat="server"> </asp:Literal>
</div>
</form>
</body>
</html>
-------------------------------------
Pagination.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 System.Text; public partial class Pagination : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
PaginationMethod();
} protected void PaginationMethod()//分页程序
{
int totalCount = 300; // 总记录数,可作为此方法的参数
int pageSize = 20; // 每页记录数,可作为此方法的参数 string url = Request.Url.AbsoluteUri.Split('?')[0]; // 基地址 int currentPage = 1; // 当前页数
if (Request["currentPage"] != null && Request["currentPage"] != "")
{
currentPage = int.Parse(Request["currentPage"].ToString().Trim());
} int totalPage = (totalCount - 1) / pageSize + 1; //总页数
int startPage = 1; // 起始页数
int endPage = totalPage; //结束页数 // 分页信息
this.paginationInfo.Text = "共 <font color=red>" + totalCount + " </font> 条记录";
this.paginationInfo.Text += ",分 <font color=red>" + totalPage + " </font> 页显示"; // 校验参数
if ((totalCount < 0) || (pageSize < 1))
{
return;
}
if (currentPage < 1)
{
currentPage = 1;
}
if (currentPage > totalPage)
{
currentPage = totalPage;
} // 设置起始页数和结束页数
if (totalPage <= 9)
{
startPage = 1;
endPage = totalPage;
}
else
{
if (currentPage <= 5)
{
startPage = 1;
endPage = 9;
}
else
{
startPage = currentPage - 4;
endPage = currentPage + 4 < totalPage ? currentPage + 4 : totalPage;
}
} // 判断首页、上一页、下一页、尾页的链接是否可用
bool firstIsEnable = true;
bool preIsEnable = true;
bool nextIsEnable = true;
bool lastIsEnable = true;
if (totalPage == 1)
{
firstIsEnable = false;
preIsEnable = false;
nextIsEnable = false;
lastIsEnable = false;
}
else if (currentPage == 1)
{
firstIsEnable = false;
preIsEnable = false;
}
else if (currentPage == totalPage)
{
nextIsEnable = false;
lastIsEnable = false;
} // 生成分页结果
StringBuilder sResult = new StringBuilder();
// 1.首页
sResult.Append(LinkStyle(url, 1, "首页", firstIsEnable));
// 2.上一页
sResult.Append(LinkStyle(url, currentPage - 1, "<<", preIsEnable));
// 3.中间页数
for (int i = startPage; i <= endPage; i++)
{
bool linkIsEnable = true;
if (i == currentPage)
{
linkIsEnable = false;
}
sResult.Append(LinkStyle(url, i, i.ToString(), linkIsEnable));
}
// 4.下一页
sResult.Append(LinkStyle(url, currentPage + 1, ">>", nextIsEnable));
// 5.尾页
sResult.Append(LinkStyle(url, totalPage, "尾页", lastIsEnable));
this.paginationResult.Text = sResult.ToString();
}
protected string LinkStyle(string url, int pageIndex ,string id,bool linkIsEnable) // 这里可改变分页样式
{
string result;
if (linkIsEnable)
{
result = " <span> <a href=\"" + url + "?currentPage=" + pageIndex + "\">" + id + " </a> </span> ";
}
else
{
result = " <span>" + id + " </span> ";
}
return result;
}
}
-------------------------------------
然后再找个通用存储过程,结合起来很好使的
http://blog.csdn.net/amandag/archive/2008/08/05/2773541.aspx
Repeater实例.DataSource=PagedDataSource实例;
Repeate实r实例.DataBind();
程序员总是有自己造轮子的冲动
建议使用AspNetPage
http://www.cnblogs.com/csharp-net/archive/2007/11/26/973093.html