Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access all rows of gridview (not just current page)

Posted on 2006-10-30
7
Medium Priority
?
239 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

715 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