日期:2014-05-18  浏览次数:20443 次

散尽分求.net列表页生成方案,带分页的
散尽分求.net列表页生成方案,带分页的


------解决方案--------------------
看看这个网页,我做的

http://www.39un.com/bbs/Content/T---3943---1.html

这个页面是通过JS输出翻页代码,在JS中配置总页数! 其他你在这个基础上想想吧! 这样做的优点是不用每次都要生成旧的页面!
------解决方案--------------------
o_o
------解决方案--------------------
一般的翻页控件一个是为了添加更多的样式和功能,一个是在大数据量的情况下,只读取需要的内容到内存中来提高服务器的性能;
只要能够做到后面一点,就需要有存储过程的支持,网上这样的翻页功能很多的啊
------解决方案--------------------
ASP.NET2.0中datalist仿百度分页
我本人做的时候用的是MYSQL数据库, 测试时请转化到MSSQL数据库即可
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 MySql.Data.MySqlClient;
using System.Data.SqlClient;
using System.IO;
public partial class mysql : System.Web.UI.Page
{
MySqlConnection conn = new MySqlConnection(System.Configuration.ConfigurationManager.AppSettings["constrmy"]);
int ToatalCountRecord;//总记录数
int PageItem = 4;//每页显示的条数
int CurrentPage = 1;//当前页数
protected void Page_Load(object sender, EventArgs e)
{

if (!this.Page.IsPostBack)
{
if (Request.QueryString["page"] != null)
{
if (!Int32.TryParse(Request.QueryString["page"].ToString(), out CurrentPage))
{
Response.Write("请输入分页参数!");
Response.End();
return;
}
}

this.BuidGrid();
}
}

private void BuidGrid()
{
string s2 = "select * from ts1";
MySqlDataAdapter da = new MySqlDataAdapter(s2, conn);
DataSet ds = new DataSet();
int startRecord = (CurrentPage - 1) * PageItem;
da.Fill(ds, startRecord, PageItem, "a");
this.DataList1.DataSource = ds.Tables["a"].DefaultView;
this.DataList1.DataBind();
MySqlCommand comm = new MySqlCommand("select count(*) from ts1", conn);
conn.Open();
ToatalCountRecord = Convert.ToInt32(comm.ExecuteScalar());
conn.Close();
BuildPages();
}
private void BuildPages()
{
int Step = 5;//偏移量
int LeftNum = 0;//做界限
int RightNum = 0;//右界限
string PageUrl = Request.FilePath;
int PageCount = (int)Math.Ceiling((double)(ToatalCountRecord) / PageItem);
if (CurrentPage - Step < 1)
{
LeftNum = 1;
}
else
{
LeftNum = CurrentPage - Step;
}
if (CurrentPage + Step > PageCount)
{
RightNum = PageCount;
}
else
{
RightNum = CurrentPage + Step;
}
string OutPut = "";
if (CurrentPage > 1)
{
OutPut += "<a href='" + PageUrl + "?page=" + (CurrentPage - 1) + "'>" + "上一页" + "</a>";
}
for (int i = LeftNum; i <= RightNum; i++)
{
if (i == CurrentPage)
{
OutPut += "<font color=red>" + " " +"["+i.ToString() +"]"+ "" + "</font>";
}
else
{