Solved

Display records in blocks in gridview?

Posted on 2011-09-03
21
404 Views
Last Modified: 2012-05-12
I would like to be able to display records on my gridview in blocks.

So when the page loads, it will display 20 records, and at the bottom of the grid, there will be a button or link that says "Display more records". When I click on that, it will display another 20 records and now I will have 40 records displayed on my webform.

How can this be done? The gridview is currently databound to a dataview.

Thanks.
0
Comment
Question by:MyersA
  • 10
  • 8
  • 3
21 Comments
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 36478086
Yes, you can, the better way is to control the rows returned for your query, you can do someting like this in your DB side (this syntax is supported since SQL Server 2005):
SELECT TOP (@pTop)
	*
FROM
	dbo.MyTable

Open in new window

So @pTop can be a parameter of your query or sp, then in your aspx page you can have a parameter starting with the value 20, then when you click the "Display more records" button you can increment this value (+20) that will be passed to your query or sp as a parameter.

Do you have the idea? if not, feel free in ask.

I hope this help.
0
 
LVL 2

Author Comment

by:MyersA
ID: 36478132
THanks for the post.

The problem is that it may start at 20 records, but if the user decides to view all the records, the gridview may end up being bound to 1000 records, which will be quite a burden. Essentially, I would be doing a gridview.bind for 20, 40, 60,...1000, 1020 records, and so on, right?

I will be displaying friendbook friends, and it's not unusual for a member to have thousands of friends. So binding my gridview to a 5,000-record dataview will be tough.

facebook has this same functionality, and I'm certain they don't do a round-trip to the server every time someone wants to look at a few more records. How do they do it?
0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 36478177
Well buddy, you need to combine techniques, from server logic to client logic, is hard to me give you a direct solution for that, because it depends of your project requirements, data structure, etc...

I can give you this idea, you can do a server logic that sent to the client a limited result-set at first (again this depends in how yours members frequently access this data), save it in a dynamic array on your client browser (by using JASON, AJAX technologies), then handle your display logic that will consume this data, if more data is required you need to do another round-trip to the server and sent more records, all this in a way that avoid several round-trips to the server.

I hope this is useful for you...
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 2

Author Comment

by:MyersA
ID: 36478247
Would you happen to know of any links that can possibly point me to the right direction?

Out of curiosity, and this is the reason I posted this question (but it is totally unrelated), would you happen to know why gridview.OnPageIndexChanging doesn't fire with __EVENTTARGET, __EVENTARGUMENT hidden fields?

I'll understand if you don't want to reply to this question.

Thanks.
0
 
LVL 2

Author Comment

by:MyersA
ID: 36478253
If I add the following two fields, gridview.OnPageIndexChanging doesn't fire. Otherwise, it does.

<input type ="hidden" name ="__EVENTTARGET" value ="" />
<input type ="hidden" name ="__EVENTARGUMENT" value ="" />
0
 
LVL 17

Accepted Solution

by:
Carlos Villegas earned 200 total points
ID: 36478296
Hello, google is friend:
http://www.google.com/search?aq=1&oq=paging+with+ajax&gcx=c&sourceid=chrome&ie=UTF-8&q=paging+with+ajax+in+asp+net

I like this example that implement paging by using AJAX:
http://www.asp.net/ajax/videos/how-do-i-implement-the-ajax-paging-pattern

Related to your other question, is of my knowledge that __EVENTTARGET, __EVENTARGUMENT are reserved fields used by asp.net, I don't known what happen if you play with this.
0
 
LVL 4

Assisted Solution

by:Friman001
Friman001 earned 200 total points
ID: 36478931
What you are looking for is the use of the Server Explorer to create your gridview.  Click View > Server Explorer.  In this, you will need to set up your connection to your SQL database by clicking the icon for "Connect to Database" and then you will need to enter the correct information with the username and password if it is secured.  After that, find the table that you would be wanting to pull the data from by opening your database connection in the Server Explorer (after you added it of course!), expanded the Tables folder, and then drag your table into your Webform (.aspx page) and a gridview will be created.  The GridView tasks window should open, but if it doesn't, select the gridview and click the arrow that shows up on the top right cornor of the gridview.  There, will see options for paging, sorting, editing, deleting, and selection.  Hope this helps!!!
0
 
LVL 4

Expert Comment

by:Friman001
ID: 36478932
Sorry it is all in one big lump and not seperated into paragraphs!
0
 
LVL 4

Expert Comment

by:Friman001
ID: 36478938
You can also click the "Auto Format" at the top of the GridView Tasks dialog box to change the look of the GridView.
0
 
LVL 4

Expert Comment

by:Friman001
ID: 36481055
Where my comments what you were looking for?
0
 
LVL 4

Expert Comment

by:Friman001
ID: 36481058
Were*
0
 
LVL 2

Author Comment

by:MyersA
ID: 36496397
@Friman001: Thanks for the comments.

You're explaining how to create a gridview with a data source. I am finding a way to display records in a gridview in blocks, similar to facebook's scrolling function.
0
 
LVL 4

Expert Comment

by:Friman001
ID: 36510852
@MyersA: That method will allow you to enable paging, which was what I got out of your post.  Display 20 records and have an option to click a page number to display the next 20 records.

Is that not what you were asking about?
0
 
LVL 2

Author Comment

by:MyersA
ID: 36587694
I know how to create a gridview that allows paging.

What I wanted to do was that when the page loads, it will display 20 records, and at the bottom of the grid, there will be a button or link that says "Display more records". When I click on that, it will display another 20 records and now I will have 40 records displayed on my webform.

If you have a facebook profile, you'll notice that you will initially see X records. When you click on the link on the bottom it will display 20 more records without posting back.

It seems this can be done with json and web services, but I ended going another direction.
0
 
LVL 4

Expert Comment

by:Friman001
ID: 36896821
Just dynamically add more rows the the grid.
0
 
LVL 4

Expert Comment

by:Friman001
ID: 36896827
Sorry for messing up your post.  I think you should be able to change the amount of records in the view from the code behind file.  Add a button at the bottom, so when you click it, it will add 20 more records to show up in the GridView.  I do not know if this can be done but, if you can set how many show up at first through the properties of the GridView, then you can dynamically change it when a button is clicked.
0
 
LVL 2

Author Comment

by:MyersA
ID: 36897838
THanks for the reply.

The problem there is that it will have to go back to the server, and that's the issue I want to avoid. This can be done with javascript, but it's a more complicated solution. IF you go to facebook, you'll notice that facebook will continue showing friends when you scroll down. And it never refreshes.
0
 
LVL 4

Expert Comment

by:Friman001
ID: 36908028
If you want a button that you can click to load more data, just add a method to the code behind file.  When you click the button, have it create more rows in the codebehind file, and then add them to the gridview.  I actually have a site that inserts labels and textboxes into a table (which you could do too) when you click the button.

Just create a table, add a row using that table id in the code behind file, insert a cell into that tablerow and add things to that cell.  If this pertains to you, let me know and I can give you examples.  If you never want to make a call back to the database server, if that is what you are using, then you will have to load all the data into a datatable and make calls as you need it.
0
 
LVL 2

Author Comment

by:MyersA
ID: 36934596
That way, the webform wil go back to the server and then it will post back. It will do a refresh. That's not how I want to do it. And I don't want to load all the data into the table.

There is a way to do this, but it involves using json and webservices.
0
 
LVL 4

Expert Comment

by:Friman001
ID: 36938838
That is out of my area.  I have never heard of json.  I have heard of webservies but, I have never used them.  Try Google'ing if you already know what you are looking for or wait for someone else to come along to the thread.

Sorry I could not help!
0
 
LVL 2

Author Closing Comment

by:MyersA
ID: 37071407
thanks.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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