Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with a gridview, paging and "object reference not set" error

I'm stuck with the following problem. I'm trying to implement a basic GridView paged result set, which connects to an Oracle database. By itself, the GridView, and the paged results, work fine. The problem comes when I try to put it in page layout class that we have at work.

We have ClassA, which inherits from Page, and is a corporate standard. Then I have ClassB, which inherits from ClassA and which includes application-specific code. The page that the GridView is on inherits from ClassB. This all seems to work fine in other pages, and I don't think it's the source of the problem, but I thought I'd mention it.

What happens is that the first time the page with the GridView loads, everything looks normal. The query runs and the first 10 records are displayed, with the numbers for paging below. When I click on "2" or any of the other pages, I get the "yellow screen of death" with the following message: "Object reference not set to an instance of an object". The object being referred to in that error line is "Me", the Page object (ASP.pagename_aspx in the debugger). I don't believe that the exact line it fails on is that important, because I've switched the order of a few statements around and it just fails on the earliest one.

I've traced through with the debugger and it looks normal, only that on Page 1 it works fine, and Page 2 it fails.

I have implemented the PageIndexChanging event (again, it works by itself if I remove inheritance from ClassB. Also, if I try inheriting directly from ClassA (bypassing ClassB entirely), I still get the problem.

Any ideas? Thanks.


1 Answers

I ran into a similar situation where the base (ClassA in your example) had variables that were set up to handle all the paging and sorting bits, and the GridView was wired up to events that used those variables. Not setting the proper base class variables in my page caused the exact same sort of error.

like image 194
Harper Shelby Avatar answered Feb 26 '26 07:02

Harper Shelby