![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
datalistbind();
}
}
public void datalistbind()
{
int curpage = Convert.ToInt32(this.lblPage.Text);//将label中的值赋值给一个变量
PagedDataSource psd = new PagedDataSource();//实例化对象
SqlText = "select R_id,S_id,R_subjiect,R_words,R_time,UserName,User_Style,UserScore, Grade ,H_Image from Users,Grade,Headphote,Response where Users.UserName=Response.R_name and Headphote.H_Name=Users.UserHead and Users.G_id=Grade.G_id and S_id=" + ViewState["S_id"] + "";
//opr.datalistbind(SqlText, DataList1);
psd.DataSource = dbbase.ExecuteSQLGetDataTable(SqlText).DefaultView;//绑定数据源
psd.AllowPaging = true;//应许分页
psd.PageSize = 5;//每页两条数据
psd.CurrentPageIndex = curpage - 1;//设置索引
//将按钮设置为可点击
this.IbtnLast.Enabled = true;
this.IbtnFirst.Enabled = true;
this.IbtnUP.Enabled = true;
this.IbtnNext.Enabled = true;
if (curpage==1)//当当前页为1是 设置不可点击
{
this.IbtnFirst.Enabled = false;
this.IbtnUP.Enabled = false;
}
if (curpage == psd.PageCount)//当当前页为最后页是 设置不可点击
{
this.IbtnNext.Enabled = false;
this.IbtnLast.Enabled = false;
}
this.lblpageCount.Text = Convert.ToString(psd.PageCount);//设置总页数
this.DataList1.DataSource = psd;//绑定datalist
this.DataList1.DataBind();
}
protected void IbtnFirst_Click(object sender, ImageClickEventArgs e)//点击首页绑定
{
this.lblPage.Text = "1";
datalistbind();
}
protected void IbtnUP_Click(object sender, ImageClickEventArgs e)//点击上一页 更改页码
{
this.lblPage.Text = Convert.ToString(Convert.ToInt32(this.lblPage.Text)- 1);
datalistbind();
}
protected void IbtnNext_Click(object sender, ImageClickEventArgs e)
{
this.lblPage.Text = Convert.ToString(Convert.ToInt32(this.lblPage.Text) + 1);//点击下一页 更改页码
datalistbind();
}
protected void IbtnLast_Click(object sender, ImageClickEventArgs e)//点击末页绑定
{
this.lblPage.Text = this.lblpageCount.Text;
datalistbind();
}
--------------------------------------------------------------------------
今天,明天就在此刻!此刻奋斗,今天耕耘,明天收获,明天辉煌!此刻放弃, 今天无为,明天饥饿,明天黯淡!
JimmyCai
posted on
2009-05-21 20:54
JimmyCai
阅读(
258)
评论()
编辑
收藏
举报