上一篇文章中的使用方法在只有显示,没有其他操作时好用,归根结底是对控件的认识不够,点击分页的时候,页面会刷新一次,造成搜索条件发生后,又重新进行初始化绑定;PagedDataSource pds 存在一个问题,也希望看到这篇文章的大神们可以帮着解决,就是没有搜索或者删除操作时,AspNetPager1_PageChanged事件,直接是Databind(),如果采用下面的代码,每次changed事件,都是在重新加载一遍,而且如果gridview的DataSource不绑定pds,不能点击aspnerpage的页码进行下一页操作。
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;//索引同步
pds.CurrentPageIndex = 0;
pds.DataSource = dt.DefaultView;
GridView1.DataSource = pds;//数据绑定
GridView1.DataBind();
AspNetPager1.RecordCount = dt.Rows.Count;
参考同事使用的情况,不进行pds操作,直接进行pds操作,只是每次绑定AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0][0]);,所以动手将Databind()函数修改为Databind(int index),index传递当前页码,相应的AspNetPager1_PageChanged事件改为Databind(AspNetPager1.CurrentPageIndex),初始化的时候改为Databind(1);
public void Databind(int index)