gridview+objectdatasource+aspnetpager如何整合
这篇文章主要为大家展示了"gridview+objectdatasource+aspnetpager如何整合",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"gridview+objectdatasource+aspnetpager如何整合"这篇文章吧。
前台代码:
OnRowCommand="viewIShow_RowCommand" PageSize="2"
OnPageIndexChanging="viewIShow_PageIndexChanging"
OnDataBound="viewIShow_DataBound">
InsertMethod="Add" SelectMethod="GetList" TypeName="AUDIOSYSTEM.BLL.ishow"
UpdateMethod="Update" OnSelected="ObjectDataSource1_Selected">
PropertyName="Text" Type="DateTime" />
后台代码:
protected void myPage_PageChanged(object sender, EventArgs e)
{
GridViewRow pagerRow = viewIShow.BottomPagerRow;
AspNetPager myPage = (AspNetPager)pagerRow.Cells[0].FindControl("myPage");
viewIShow.PageIndex = myPage.CurrentPageIndex - 1;
}
protected void viewIShow_DataBound(object sender, EventArgs e)
{
GridViewRow pagerRow = viewIShow.BottomPagerRow;
AspNetPager myPage = (AspNetPager)pagerRow.Cells[0].FindControl("myPage");
GridView view = (GridView)sender;
myPage.PageSize = view.PageSize;
myPage.CurrentPageIndex = view.PageIndex +1; //GridView分页索引是从0开始,AspNetPager是从1开始的
}
protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
DataSet ds = (DataSet)e.ReturnValue; //ObjectDataSource查询方法返回什么类型就转成什么类型
GridViewRow pagerRow = viewIShow.BottomPagerRow;
AspNetPager myPage = (AspNetPager)pagerRow.Cells[0].FindControl("myPage");
if (ds == null)
{
myPage.RecordCount = 0;
}
else
{
myPage.RecordCount = ds.Tables[0].Rows.Count;
}
}
以上是"gridview+objectdatasource+aspnetpager如何整合"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!