Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

Access all rows of gridview (not just current page)

I have a user control with a gridview object that has 10 pages (they are results of a user search).
I am exposing the gridview as such:

        public GridView SearchResultsGrid
        {
            get { return GridView1; }
        }

I am trying to access this property from a different page but the problem is that I only have access to the first 10 rows due to the .PageSize property of GridView1.

Is there a way, from a separate page, to retrieve a GridView object that contains all rows, regardless of the pagesize property or how many pages there are?
0
Mr_Snrub
Asked:
Mr_Snrub
  • 3
  • 3
1 Solution
 
jnhorstCommented:
In short, no.  The only thing I can think of is exposing the AllowPaging property so you can turn it off and then access all the rows.

John
0
 
Mr_SnrubAuthor Commented:
Good idea, I'll try it out and let you know.
0
 
Mr_SnrubAuthor Commented:
Nope, that didn't work. After modifying the AllowPaging property and re-binding it loses the datasource. The problem is (to make a long story short) I do not have access to the datasource from the calling page.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jnhorstCommented:
Do you have access to the code for the user control itself?

John
0
 
Mr_SnrubAuthor Commented:
Yes, I have access to all the code, but the problem is that the datasource is a datatable generated from a keyed collection that is dynamically generated from the database, and I've tried exposing the DataTable that is generated from the database, but when I go to access the DataTable property from the calling page it is empty (a postback issue maybe?).

Hope this makes sense.
0
 
jnhorstCommented:
Yes, I think this would be a postback issue.  If you are generating the data table in Page_Load inside an if block where you are checking to see if the page is not a postback, then it will not generate when you change the AllowPaging property and post that change back.

The general rule I follow for data grid type displays is this: Get the data (and generate the data source, if you do this dynamically) OUTSIDE of any "if not is postback" block.  Then call DataBind on the grid INSIDE the if block.  In other words, always build out the data source (postback or not postback) but only bind the control in Page_Load when the page is not a postback.

If you have a button either on the page or as part of the user control, you want to change the AllowPaging property and then call DataBind on the grid (for this reason it might be better to have the button as part of the user control).  You have to remember that when you click a server side button, Page_Load fires first, then the click event for the button (or whatever control-event fired the postback).

You would surprised how many issues are posted on this board that end up being a matter of when data is loaded and DataBind is called vis-a-vis the page being not a postback or a postback.

John
0
 
deanvanrooyenCommented:
if you are using paging then the datagrid will only containt the page count of records eg only 10 because the sql is only returning 10 records, best off writting a sproc to get the data you want.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now