62,220
社区成员




//分页赋值
protected void GetPageCount()
{
SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter oda = new SqlDataAdapter("select * from ts", conn);
oda.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "ts");
AspNetPager1.AlwaysShow = true;
SqlCommand cmd = new SqlCommand("select count(*) from ts", conn);
cmd.Connection = conn;
AspNetPager1.RecordCount = (int)cmd.ExecuteScalar();//获取表中信息的数量
GridView1.DataSource = ds;
GridView1.DataBind();
ds.Dispose();
conn.Close();
GC.Collect();
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
GetPageCount();
}
}
//设置当前显示页为最后一页
this._gridview.PageIndex = this._gridview.PageCount-1;
this._gridview.DataBind();
//最后一页的行数
int lastSize = this._gridview.Rows.Count;
//计算出总行数
int rowsCount = this._gridview.PageSize*(this._gridview.PageCount-1)+lastSize;
//最后记得把Index设为0,即显示第一页
this._gridview.PageIndex = 0;