日期:2014-05-17 浏览次数:20503 次
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0)
{
e.Row.Cells[0].Text = Convert.ToString(e.Row.DataItemIndex + 1);
}
}
int pageCount;//总页数
int currentPage = 1;//第定义当前页
private void Bind()
{
OracleConnection conn = new OracleConnection(ConnectionString);
string str = "select * from order order by id desc";
OracleDataAdapter da = new OracleDataAdapter(str, conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
//创建数据源
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
//允许分页
pds.AllowPaging = true;
//设置每页显示记录数
pds.PageSize = int.Parse("10");
//获取总页数
pageCount = pds.PageCount;
Label2.Text = pageCount.ToString();
pds.CurrentPageIndex = currentPage - 1;
//当前页
Label1.Text = Convert.ToString(currentPage);
LinkButton1.Enabled = true;
LinkButton2.Enabled = true;
LinkButton3.Enabled = true;
LinkButton4.Enabled = true;
if (Label1.Text == "1")
{
LinkButton1.Enabled = false;
LinkButton2.Enabled = false;
}
if (Label1.Text == Label2.Text)
{
LinkButton3.Enabled = false;
LinkButton4.Enabled = false;
}
GridView1.DataSource = pds;
GridView1.DataBind();
}
//首页
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (this.Label1.Text == "1")
{ }
else
{
currentPage = 1;
Bind();
}
}
//上一页
protected void LinkButton2_Click(object sender, EventArgs e)
{
if (this.Label1.Text != "1")
{
currentPage = int.Parse(this.Label1.Text) - 1;
this.Label1.Text = currentPage.ToString();
Bind();
}
}
//下一页
protected void LinkButton3_Click(object sender, EventArgs e)
{
if (this.Label2.Text == this.Label1.Text)
{
}
else
{
currentPage = int.Parse(this.Label1.Text) + 1;
this.Label1.Text = currentPage.ToString();
Bind();
}
}
//末页
protected void LinkButton4_Click(object sender, EventArgs e)
{
if (this.Label2.Text != this.Label1.Text)
{
this.Label1.Text = this.Label2.Text;
currentPage = int.Parse(this.Label1.Text);
Bind();
}
}