Solved

Access all rows of gridview (not just current page)

Posted on 2006-10-30
7
230 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now