在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
前台代码: 复制代码 代码如下: <asp:GridView ID="viewIShow" runat="server" DataSourceID="ObjectDataSource1" AllowPaging="True" AutoGenerateColumns="False" OnRowCommand="viewIShow_RowCommand" PageSize="2" OnPageIndexChanging="viewIShow_PageIndexChanging" OnDataBound="viewIShow_DataBound"> <Columns> </asp:TemplateField> 后台代码: 复制代码 代码如下: 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; } } |
请发表评论