Solved

Access all rows of gridview (not just current page)

Posted on 2006-10-30
7
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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