Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid AllowPaging Option

Status
Not open for further replies.

CodingIsFun

Programmer
Apr 9, 2004
134
US
I am new to .NET and having some issues using some of the datagrid options.

I have figured out how to bind data to the grid, but when I make the dg.allowpaging = true; I get all sorts of weird errors. Just incase anyone asks the grid works perfectly fine with this setting set to false. Is there extra code I need to use to actually have the paging work properly? Does anyone have some snippets that can help point me in the right direction.

thanks in advance.
 
Yes there are extra steps. You can't just set it to "Allow paging", but I really wish that you could. Try this...
Code:
Private Sub dgBreed_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgBreed.PageIndexChanged
        'This allows paging of data
        dgBreed.CurrentPageIndex = e.NewPageIndex
        'This will bind the data again (you need this!)
        BindData()
    End Sub
You will no doubt have your own method to bind the data but the important part is the e.NewPageIndex. It is going to keep your place when you start "flipping" pages. For tons of stuff on the datagrid check out If you want to skip to the last lesson and read the first article which will tell you what has previously been discussed, you can then skip to the ones you need.
 
I tried your sample and got this error upon the page loading.

AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID dgRooms when AllowPaging is set to true and the selected datasource does not implement ICollection.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID dgRooms when AllowPaging is set to true and the selected datasource does not implement ICollection.

Source Error:


Line 59: Rooms rooms = new Rooms();
Line 60: dgRooms.DataSource = rooms.GetRooms(int.Parse(lstProperty.SelectedValue));
Line 61: dgRooms.DataBind();


When I change allowcustompaging to true I don't even get active paging <> symbols.

I tried clicking on the link you provided and received a page not found error..

thanks for the help so far.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top