Solved

Access all rows of gridview (not just current page)

Posted on 2006-10-30
7
235 Views
Last Modified: 2007-12-19
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
Comment
Question by:Mr_Snrub
  • 3
  • 3
7 Comments
 
LVL 10

Expert Comment

by:jnhorst
ID: 17838248
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
 

Author Comment

by:Mr_Snrub
ID: 17838259
Good idea, I'll try it out and let you know.
0
 

Author Comment

by:Mr_Snrub
ID: 17838787
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 10

Expert Comment

by:jnhorst
ID: 17838838
Do you have access to the code for the user control itself?

John
0
 

Author Comment

by:Mr_Snrub
ID: 17838854
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
 
LVL 10

Accepted Solution

by:
jnhorst earned 500 total points
ID: 17838909
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
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17840170
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I prevent the pages in my site from showing up in a google search? 2 77
Web site error 3 39
ASP.net Show "please wait " message as page loads 2 41
IIS redirect 1 67
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question