Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pagination in DataGrid 1

Status
Not open for further replies.

vbkris

Programmer
Jan 20, 2003
5,994
IN
hi,

i have set pagination in datagrid. It contains some checkboxes. I want to find out the checkbox that has been checked. For this i use:

For Each di In DataGrid1.Items
'cb = di.FindControl("cb")
cb = CType(di.FindControl("chk"), CheckBox)


Now i have a question, does this for loop check ALL the records or only those records that are displayed in that particular page???

e.g:
Total - 100 records
Displayed - 10 records.

The for loop will now check through 10 records or 100 records???


Known is handfull, Unknown is worldfull
 
I guess the easiest way for you to check would be:
Code:
Dim i as Integer = 0
For Each di In DataGrid1.Items
i += 1
Next
Response.Write(i)


--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
will try that and get back to you...

Known is handfull, Unknown is worldfull
 
i will now tell you why i wanted that info:

The only control that allows inbuilt pagination is datagrid. The book i read says that it caches data.
But it seems that everytime i change the page number i have to ReBind the data, i.e it has to connect the database everytime the page changes. So where is that cache used? Isnt that a very cumbersome process?

The next doubt:
Once i came across the word cache i read through what it is. Caching can be used only for items that do not dynamically. But a datagrid represents a database that cn change at any time(By adding a record or modifying a record, this action may not be through the datagrid). So how does caching help here?

Can i have a reference site that explains this kind of info? Many sites seem to display only the methods and how to use them. Not many tell how the process happens.

If the datagrid is recaching for every page i wouldnt even bother using it. Not many ISP will allow it (AS cache = memory usage, so the server must crash at one point as each user will have a seperate cache). So there must be some advantage that i must be missing...


Known is handfull, Unknown is worldfull
 
any takers???

Known is handfull, Unknown is worldfull
 
There's actually some reasonable information on what you're talking about in the .Net SDK Documentation.

Remember you can control Caching at a Page, Fragment of a Page and at an Application Level. There are articles around if you Google for them...

Rhys

"Vampireware /n/,a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."

"I see dead pixels!
 
i tried the SDK, all it gave me was like is said info on datagrid. Maybe i am searching for the wrong keywords???

And regarding caching i want to know how the datagrid data is cached? like i said the data that i want to dislay changes often. so why even cache???

Known is handfull, Unknown is worldfull
 
A search for 'cache' in the SDK documentation get's me quite a decent chunk of info. and design decisions such as caching frequently changing data are best made by the person with an understanding of the implications within the application - you.

Try the SDK doc's again or just click the Google link in my post above...

Rhys

"Vampireware /n/,a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."

"I see dead pixels!
 
will look out at the cache part and come back to you. cache is only incidental to the question. DataGrid is much more important...

Known is handfull, Unknown is worldfull
 
I disagree. Remember - OOP - A DataGrid is just a type of WebControl which is just another type of object etc. etc

It's the Caching that's important and, subsequently, how it is or isn't implemented for the particular object (which just happens to be a DataGrid) in question and potentially it's Parent/Child objects.

Rhys

"Vampireware /n/,a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."

"I see dead pixels!
 
i have a book here that says:
"For every page thats called the datagrid has to rebind itself" which means that it has to connect to the database again. my question is why it requires caching when it connects to the database everyime???

Known is handfull, Unknown is worldfull
 
It says a datagrid has to rebind itself, not that it has to re-query the database, retreive the data it wants and then re-bind itself. You can add a DataTable to the Cache or Viewstate, re-call it from there and re-bind a DataGrid to it without going back to the database.

Without wishing to be rude, the information is out there so go and look for it instead of expecting to be spoon fed an answer, or have someone else do what you can do just as easily. You'll probably find you learn a lot more than what you're looking for by doing so as well, which in my experience can only ever be a good thing as it helps my understanding of these subjects.

Rhys

"Vampireware /n/,a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."

"I see dead pixels!
 
>>Without wishing to be rude, the information is out there so go and look for it instead of expecting to be spoon fed an answer:

I AM NOT LOOKING FOR WAYS TO USE A DATAGRID.

I am looking for a concept here that i am not able to find anywhere. The concept is very simple:
DataGrid caches data. WHY DOES IT DO THIS WHEN THE DATA CHANGES OFTEN (THATS WHERE CACHING COMES INTO PLAY).

Now if i am still missing something or if you find that i am LAZY then i dont know how else to put this across...


Known is handfull, Unknown is worldfull
 
a follow up:
"Now that I am porting our site to the .NET platform, I decided to revisit this problem. The built-in paging functionality in the DataGrid control still fails to scale well with large result sets. It processes all the data every time you navigate to a new page to figure out which records to display. Certain genres may contain thousands of rows, so that might cause some scalability issues.
"


now this is the issue i am talking about. If it processes all data per page isnt that resource intensive???

Known is handfull, Unknown is worldfull
 
maybe if i can give you why i wanted this question u can answer better:
i am trying to build a control that will display details as follows:

Username ActivStatus(ChkBx) Delete(ChkBx)


The above must have a pagination of 5 per page. The ActiveStatus is represented by a single char column in the database. If it is "N" then the checkbox there must be checked and the entire row must be shaded in GREY.

At the end of this grid there will be 2 buttons:
"Activate" - One shot (de)activation of all the users displayed.
"Delete" - One shot deletion of all the users displayed.

Now since the background color should change on the fly i cannot use caching here.

I have built a custom control to do all the above. But its only drawback is in pagination. If it has to display the 100th record it has to go through the first 99 records.
and since caching cannot be used i am forced to connect to the database everytime (i use a datareader).

Now i want to know if a datagrid is effective here. The custom control i developed will go through only the first 99 records to display the 100th record, but the datagrid seems to go through ALL the records before finding the correct record.

Now there is a perforamce issue here.

Am i clear now? or am i approaching the problem in the wrong way (some other control that i have missed)...

Known is handfull, Unknown is worldfull
 
and ca8msm:
the items collection only returns the items displayed in the page. Thanks for the tip on that...

Known is handfull, Unknown is worldfull
 
I can see your point far easier when knowing the intended use but there ways around your issues.

You could paginate at the database only returning the subset group of records you want.

You could paginate a datatable and utilise this as the datasource for the datagrid.

If you don't want your page (or fragment of a page such as a datagrid or control on it) cached, don't cache it, this is under the control of the site, page and code you write. Look at the web aplication setup in IIS and change it so content expires immediately and put code in the page so it isn't cached - you have control over this. This isn't a situation where something is cached whether you want it to be or not, it is controlled by the site, page and application setup, by you and the code you write.

Sorry, but I don't really see the issue here. Pages are cached at client and server based on the application and Web Application configuration, and therefore it is us, the programmers. that are responsible for managing the caching functionality of our applications. To me the DataGrid control is just another type of WebControl and is behaving as I would expect any WebControl to behave in being cached, however it is down to you to control the minutae detail of your application and if you don't want your user control cached you should just have to set a cache policy for it such as;
Code:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
...in the overridden OnInit page event of you user control.

Bottom line, a DataGrid is Cached because it's a type of WebControl and WebControls are cached, and if you don't want it cached, code it. It's that simpe as I understand it.

Rhys

"Vampireware /n/,a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."

"I see dead pixels!
 
But why does it cache? it has many update features right? when it updates a recorset the dataset that is holding the data is absolete(as it contains old data in atleast one record).
If my reading of cache concpet is correct then it is for data that NEVER CHANGES(atleast for the set time of XX).

So how does datagird deal with that? when i write a very simple datagrid with update features i never control cache anywhere. It seems to manage it on its own. Its about this that i want to know. How exactly does it manage its cache...

>>You could paginate at the database only returning the subset group of records you want.

Do you have examples? i have one but it has a condition that there be a primary key field that is integer in nature. But most of the tables i deal with have varchar data in nature...

Known is handfull, Unknown is worldfull
 
Here's a couple of links on pagination as I have no ready examples myself...

Tek Tips Thread

ASP.NET DataGrid Paging Part 2 - Custom Paging


A WebControl in itself does not manage it's own Caching. It's just a WebControl and as such follows the caching policy set at the site and page levels, unless you identify and isolate it as a control you do not want cached. Think OOP, a datagrid is just a type of WebControl and acts just as any other Web Control would, it's down to you to manage the instance of the datagrid control you have on your page.


Rhys

"Vampireware /n/,a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."

"I see dead pixels!
 
>>Think OOP, a datagrid is just a type of WebControl and acts just as any other Web Control would, it's down to you to manage the instance of the datagrid control you have on your page

Ok so by default it does not cache data. fine.

about the paging example (number two) its the same one i have, if you notice:

WHERE
ID > @FirstRec
AND
ID < @LastRec

The above works fine only on int or numeric type data not on varchar type of data.

i am going through the first one. will get back to you...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top