老問題:GridView用AspnetPager出錯
protected void Button1_Click(object sender, EventArgs e)
{
this.AspNetPager1.CurrentPageIndex = 1;
searchOrders();
}
void searchOrders()
{
DataSet ds = new DataSet();
string sql = "select ID,NAME,SCORE1,SCORE2,round(SCORE1/(SCORE1+SCORE2),2) as Percent from TEST2 ";
ds = oda.getDataSet1(sql, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "TEST2 ");
AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
GridView1.PageSize = AspNetPager1.PageSize;
AspNetPager1.AlwaysShow = true;
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
searchOrders();
}
------解决方案--------------------少了一段,应该这样:
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
searchOrders();
}