2008-11-12 49 views
1

我有一个Web应用程序正在使用具有自己的内置分页的数据存储。 PagedResult类告诉我总页数。我想这样做(我结合ASP.NET的GridView后)做到这一点:您可以“分配”ASP.NET GridView的PageCount属性吗?

MyGridView.PageCount = thePageCount; 

,然后让GridView的神奇打造分页链接,因为它通常会如果它做的事情本身。

问题是,“PageCount”是一个只读属性...所以,我怎么能做到这一点?

回答

2

要使用内置分页,GridView将与数据源进行交互。 GridView具有PageSize的可设置属性。

如果使用ObjectDataSource,则同时配置SelectMethod和SelectCountMethod。您可以修改您的PagedResult类以返回记录数而不是页数,或者将PagedResult调用包装在一个方法中,以将页计数转换为记录计数(PageCount * PageSize)。

如果您的PagedResult类仅用于支持Web应用程序,则应考虑将其修改为更像典型的分页数据源。

0

您可以创建自己的类来扩展GridView并覆盖PageCount getter方法以从PagedResult类中返回值。

+0

我已经反映在GridView,它的实际使用私有字段...所以覆盖大众“页页次”场实际上不会工作。虽然好想。 – 2008-11-13 00:21:30

0
 Dim myCount as Integer = 1 'this sets the page count to 1 
     While (oreader.Read()) 
      myCount += 1 'increments once for everytime a item is counted 
      'this sets an array for the items to go into 
      idFname = oreader.GetOrdinal("workCenter") 
      'this retrieves the values at those indices 
      fName = oreader.GetValue(idFname) 
      BulletedList1.Items.Add(fName) 
     End While 

    Catch ex As Exception 
     BulletedList1.Items.Add("No Workcenters Found") 
    Finally 
     oreader.Close() 
     oconn.Close() 
    End Try 
End If 
Me.insertItemForm.PagerSettings.PageButtonCount = myCount 'sets the page count to number of items in gridview or formview etc. 
相关问题