datalist的分页
来源:互联网 发布:html js图片轮播 编辑:程序博客网 时间:2024/05/16 15:15
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.SqlClient;
public partial class houtai_tizi_YHtiezi_chakan : System.Web.UI.Page
{
int RecoudCount;//总记录数
int PageCount;//总页数
int PageSize = 3;//每一页显示记录
int CurrentPage = 0;//单前现实的页数
protected void Page_Load(object sender, EventArgs e)
{
#region 获取总记录数
string countId = Request.QueryString["countid"];
sqlstr = "select count(*)as count from tb_hf where contId=" + countId;
ds = DB.GetDataTableBySql(sqlstr);
if (ds.Tables[0].Rows.Count != 0)
{
RecoudCount = Convert.ToInt32(ds.Tables[0].Rows[0]["count"].ToString());
}
else
{
RecoudCount = 0;
}
//获取总页数
if (RecoudCount % PageSize == 0)
{
PageCount = RecoudCount / PageSize;
}
else
{
PageCount =( RecoudCount / PageSize)+1;
}
ViewState["PageCount"] = PageCount;
this.Label1.Text = PageCount.ToString();
}
//主要代码
public void HF_Bind()
{
int StartIndex = PageSize * CurrentPage;
string countId = Request.QueryString["countid"];
sqlstr = "select * from user_hf where ContId=" + countId ;
//ds = DB.GetDataTableBySql(sqlstr);
SqlConnection con = new SqlConnection();
con.ConnectionString = DB.GetConnectString();
con.Open();
SqlDataAdapter da = new SqlDataAdapter(sqlstr,con);
da.Fill(ds, StartIndex, PageSize, "回复表");
this.DataList2.DataSource = ds.Tables["回复表"].DefaultView;
this.DataList2.DataBind();
PageCount =(int)ViewState["PageCount"] ;
Button3.Enabled = true;
Button1.Enabled = true;
Button4.Enabled = true;
Button2.Enabled = true;
if (CurrentPage == 0)
{
Button3.Enabled = false;
Button1.Enabled = false;
}
if(CurrentPage==(PageCount-1))
{
Button4.Enabled = false;
Button2.Enabled = false;
}
this.Label2.Text = (CurrentPage+1).ToString();
}
//第一页
protected void Button1_Click(object sender, EventArgs e)
{
ds.Clear();
CurrentPage = 0;
ViewState["CurrentPage"] = CurrentPage;//用状态来保存,当前页,应为每次单击后页面都会刷新,没有保存就没有下一页的数据,下同
HF_Bind();
}
//最后一页
protected void Button2_Click(object sender, EventArgs e)
{
ds.Clear();
CurrentPage=PageCount-1;
ViewState["CurrentPage"] = CurrentPage;
HF_Bind();
}
//上一页
protected void Button3_Click(object sender, EventArgs e)
{
ds.Clear();
CurrentPage = (int)ViewState["CurrentPage"];
CurrentPage = CurrentPage-1;
ViewState["CurrentPage"] = CurrentPage;
HF_Bind();
}
//下一页
protected void Button4_Click(object sender, EventArgs e)
{
ds.Clear();
CurrentPage = (int)ViewState["CurrentPage"];
CurrentPage = CurrentPage+1;
ViewState["CurrentPage"] = CurrentPage;
HF_Bind();
}
}
- DataList的分页技术
- DataList的分页
- DataList的分页技术
- datalist的分页
- DataList的分页技术
- DataList的分页
- datalist的分页
- DataList 分页的实现
- DataList的分页方法
- datalist分页的方法
- DataList分页的实现
- DataList的分页
- DataList的分页
- datalist的分页
- DataList分页的实现
- DataList的使用+分页
- Datalist的分页
- datalist分页问题的解决办法
- MultiCore Memory Management Technology in mortal kombat
- 数据库游标
- Nuint的常用属性(学习笔记1)
- OGNL表达式struts2标签“%,#,$”
- 设置windows下的快捷键,例如新建文本,新建word,新建excel
- datalist的分页
- 设计模式笔记之观察者模式(Observer Patterns)
- COL FIRST_NAME FORMAT A15
- Javascript初步
- dataGridView的计算问题(相乘)
- 《当程序员的那些狗日日子》(二十八)开展新工作
- JDBC编程
- 转载--Linux下Modules的概念及使用详解
- vc6 编译 quake3 。经过验证正确