gridview+objectdatasource+aspnetpager整合实例

前台代码:

复制代码 代码如下:

                    AllowPaging="True" AutoGenerateColumns="False"
                    OnRowCommand="viewIShow_RowCommand" PageSize="2"
                    OnPageIndexChanging="viewIShow_PageIndexChanging"
                    OnDataBound="viewIShow_DataBound">

                   
                       
                       
                       
                       
                           
                                晋级                                    ID="LinkButton2" runat="server" CommandName="down" CommandArgument='<%#Eval("id") %>'>降级
                           

                       
                   
                   
                       


                           
                               
                           
                       

                                                                            OnPageChanged="myPage_PageChanged" >
                               

                   
               

                                    DataObjectTypeName="AUDIOSYSTEM.Model.ishow" DeleteMethod="Delete"
                    InsertMethod="Add" SelectMethod="GetList" TypeName="AUDIOSYSTEM.BLL.ishow"
                    UpdateMethod="Update" OnSelected="ObjectDataSource1_Selected">
                   
                       
                                                    DefaultValue="2000/01/01 00:00:00" Name="start"
                            PropertyName="Text" Type="DateTime" />
                                                    Type="DateTime" DefaultValue="2500/01/01 00:00:00" />
                   

                   
                       
                       
                   

               


后台代码:

复制代码 代码如下:

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整合实例)