ASP.NET分页问题
usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingS...
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.OleDb;
public partial class show : System.Web.UI.Page
{
OleDbConnection OledbCon;
string strCon = @"provider = Microsoft.Jet.OLEDB.4.0;Data source = C:\Documents and Settings\Administrator\My Documents\lyb.mdb";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Paging();
}
public void Paging()
{
int m=2;
int n=2;
int curpage = Convert.ToInt32(this.cp.Text);
PagedDataSource pds = new PagedDataSource();
OledbCon = new OleDbConnection(strCon);
OledbCon.Open();
string OledbStr = "select top 8 * from lyb where lyb_id not in (select top "+m*n+" lyb_id from lyb order by lyb_id) order by lyb_id desc";
OleDbDataAdapter odbA = new OleDbDataAdapter(OledbStr, OledbCon);
DataSet ds = new DataSet();
odbA.Fill(ds,"lyb");
pds.DataSource = ds.Tables["lyb"].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 2;
pds.CurrentPageIndex = curpage - 1;
this.Up.Enabled = true;
this.Down.Enabled = true;
this.First.Enabled = true;
this.Last.Enabled = true;
if (curpage == 1)
{
this.First.Enabled = false;
this.Up.Enabled = false;
}
if (curpage == pds.PageCount)
{
this.Down.Enabled = false;
this.Last.Enabled = false;
}
this.LabPageBack.Text = Convert.ToString(pds.PageCount);
this.Repeater1.DataBind();
//this.Repeater1.DataSource = pds;
OledbCon.Close();
}
protected void First_Click(object sender, EventArgs e)
{
this.cp.Text = "1";
this.Paging();
}
protected void Up_Click(object sender, EventArgs e)
{
this.cp.Text = Convert.ToString(Convert.ToInt32(this.cp.Text) - 1);
this.Paging();
}
protected void Down_Click(object sender, EventArgs e)
{
this.cp.Text = Convert.ToString(Convert.ToInt32(this.cp.Text) + 1);
this.Paging();
}
protected void Last_Click(object sender, EventArgs e)
{
this.cp.Text = this.LabPageBack.Text;
this.Paging();
}
}
请问为什么没分起?而且没报错。。其实是分起页了,只是没分对,
比如我有8条记录,没页显示2条记录,这样算来就是4页。。。但是``每页都有8条记录,而且还是分了4页除来。。请问哪错了?? 展开
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.OleDb;
public partial class show : System.Web.UI.Page
{
OleDbConnection OledbCon;
string strCon = @"provider = Microsoft.Jet.OLEDB.4.0;Data source = C:\Documents and Settings\Administrator\My Documents\lyb.mdb";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Paging();
}
public void Paging()
{
int m=2;
int n=2;
int curpage = Convert.ToInt32(this.cp.Text);
PagedDataSource pds = new PagedDataSource();
OledbCon = new OleDbConnection(strCon);
OledbCon.Open();
string OledbStr = "select top 8 * from lyb where lyb_id not in (select top "+m*n+" lyb_id from lyb order by lyb_id) order by lyb_id desc";
OleDbDataAdapter odbA = new OleDbDataAdapter(OledbStr, OledbCon);
DataSet ds = new DataSet();
odbA.Fill(ds,"lyb");
pds.DataSource = ds.Tables["lyb"].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 2;
pds.CurrentPageIndex = curpage - 1;
this.Up.Enabled = true;
this.Down.Enabled = true;
this.First.Enabled = true;
this.Last.Enabled = true;
if (curpage == 1)
{
this.First.Enabled = false;
this.Up.Enabled = false;
}
if (curpage == pds.PageCount)
{
this.Down.Enabled = false;
this.Last.Enabled = false;
}
this.LabPageBack.Text = Convert.ToString(pds.PageCount);
this.Repeater1.DataBind();
//this.Repeater1.DataSource = pds;
OledbCon.Close();
}
protected void First_Click(object sender, EventArgs e)
{
this.cp.Text = "1";
this.Paging();
}
protected void Up_Click(object sender, EventArgs e)
{
this.cp.Text = Convert.ToString(Convert.ToInt32(this.cp.Text) - 1);
this.Paging();
}
protected void Down_Click(object sender, EventArgs e)
{
this.cp.Text = Convert.ToString(Convert.ToInt32(this.cp.Text) + 1);
this.Paging();
}
protected void Last_Click(object sender, EventArgs e)
{
this.cp.Text = this.LabPageBack.Text;
this.Paging();
}
}
请问为什么没分起?而且没报错。。其实是分起页了,只是没分对,
比如我有8条记录,没页显示2条记录,这样算来就是4页。。。但是``每页都有8条记录,而且还是分了4页除来。。请问哪错了?? 展开
5个回答
2010-02-01
展开全部
this.Repeater1.DataSource = pds;
this.Repeater1.DataBind();
this.Repeater1.DataBind();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
关注。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
AspNetPager 控件,推荐你用这个试下,一个成熟的分布控件!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询