Can you assign the PageCount property to the ASP.NET GridView?

I have a web application that uses a data store that has its own built-in paging. The PagedResult class tells me the total number of pages. What I would like to do this (after binding my ASP.NET GridView) do the following:

MyGridView.PageCount = thePageCount;

      

And then the GridView will magically build the links to the pages as it normally would if it did itself.

The problem is that "PageCount" is a read-only property ... so how can I do this simply?

+1


source to share


4 answers


To use inline paging, the GridView interacts with a data source. The GridView has a custom property for PageSize.

If you are using ObjectDataSource, you customize SelectMethod and SelectCountMethod. You can modify your PagedResult class to return a record count rather than a page count, or wrap the PagedResult call in a page-to-record conversion method (PageCount * PageSize).



If your PagedResult class only exists to support a web application, you should consider modifying it to look more like a typical paged data source.

+2


source


You can create your own class that extends the GridView and overrides the getCount method to return a value from your PagedResult class.



0


source


Use an ObjectDataSource control, bind it to your GridView, and set up a handler for the SelectCoutnMethod property. You may need to write a small wrapper object for your class that retrieves data that interacts with the ObjectDataSource control.

Some links to help you:

ObjectDataSource Web Server Management Overview
ObjectDataSource Class

0


source


       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.

      

0


source







All Articles