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();
}
}