今天看了一下同事写的分页代码 虽然效率不高 但是比我的简单多了
数据量小的首选(别忘了定义gridview的pagesize)
protected void LinkButton1_Click(object sender, EventArgs e)
{
GridView1.PageIndex = 0;
BusinessWork BusinessWork = new BusinessWork();
DataTable dt = new DataTable();
dt = BusinessWork.BusinessWorkDataTable("Archives_DakfGetAll");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
if (GridView1.PageIndex - 1 >= 0)
{
GridView1.PageIndex = GridView1.PageIndex - 1;
BusinessWork BusinessWork = new BusinessWork();
DataTable dt = new DataTable();
dt = BusinessWork.BusinessWorkDataTable("Archives_DakfGetAll");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
if (GridView1.PageIndex + 1 <= GridView1.PageCount)
{
GridView1.PageIndex = GridView1.PageIndex + 1;
BusinessWork BusinessWork = new BusinessWork();
DataTable dt = new DataTable();
dt = BusinessWork.BusinessWorkDataTable("Archives_DakfGetAll");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
GridView1.PageIndex = GridView1.PageCount;
BusinessWork BusinessWork = new BusinessWork();
DataTable dt = new DataTable();
dt = BusinessWork.BusinessWorkDataTable("Archives_DakfGetAll");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
数据量小的首选(别忘了定义gridview的pagesize)
protected void LinkButton1_Click(object sender, EventArgs e)
{
GridView1.PageIndex = 0;
BusinessWork BusinessWork = new BusinessWork();
DataTable dt = new DataTable();
dt = BusinessWork.BusinessWorkDataTable("Archives_DakfGetAll");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
if (GridView1.PageIndex - 1 >= 0)
{
GridView1.PageIndex = GridView1.PageIndex - 1;
BusinessWork BusinessWork = new BusinessWork();
DataTable dt = new DataTable();
dt = BusinessWork.BusinessWorkDataTable("Archives_DakfGetAll");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
if (GridView1.PageIndex + 1 <= GridView1.PageCount)
{
GridView1.PageIndex = GridView1.PageIndex + 1;
BusinessWork BusinessWork = new BusinessWork();
DataTable dt = new DataTable();
dt = BusinessWork.BusinessWorkDataTable("Archives_DakfGetAll");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
GridView1.PageIndex = GridView1.PageCount;
BusinessWork BusinessWork = new BusinessWork();
DataTable dt = new DataTable();
dt = BusinessWork.BusinessWorkDataTable("Archives_DakfGetAll");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}