views:

1358

answers:

4

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

MyGridView.PageCount = thePageCount;

And then have the GridView magically build the pagination links as it normally would if it was doing things itself.

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

A: 

You could create your own class that extends GridView and override the PageCount getter method to return the value from your PagedResult class.

tvanfosson
I've reflected the GridView, and it's actually using a private field... so overriding the public "PageCount" field actually won't work. Good thought though.
Timothy Khouri
+1  A: 

To use the built-in paging the GridView interacts with the data source. The GridView has a settable property for PageSize.

If you use an ObjectDataSource, you configure both a SelectMethod and a SelectCountMethod. You could either modify your PagedResult class to return record count instead of page count, or wrap the PagedResult call in a method to convert page count to record count (PageCount * PageSize).

If your PagedResult class only exists to support the web app, you should consider modifiying it to behave more like a typical paged data source.

HectorMac
A: 

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

Some links to help you out:

ObjectDataSource Web Server Control Overview
ObjectDataSource Class

Robert C. Barth
A: 
       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.
Randi