Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

Display records in blocks in gridview?

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
MyersA
Asked:
MyersA
  • 10
  • 8
  • 3
2 Solutions
 
Carlos VillegasFull Stack .NET DeveloperCommented:
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
 
MyersAAuthor Commented:
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
 
Carlos VillegasFull Stack .NET DeveloperCommented:
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
Independent Software Vendors: 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!

 
MyersAAuthor Commented:
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
 
MyersAAuthor Commented:
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
 
Carlos VillegasFull Stack .NET DeveloperCommented:
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
 
Friman001Commented:
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
 
Friman001Commented:
Sorry it is all in one big lump and not seperated into paragraphs!
0
 
Friman001Commented:
You can also click the "Auto Format" at the top of the GridView Tasks dialog box to change the look of the GridView.
0
 
Friman001Commented:
Where my comments what you were looking for?
0
 
Friman001Commented:
Were*
0
 
MyersAAuthor Commented:
@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
 
Friman001Commented:
@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
 
MyersAAuthor Commented:
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
 
Friman001Commented:
Just dynamically add more rows the the grid.
0
 
Friman001Commented:
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
 
MyersAAuthor Commented:
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
 
Friman001Commented:
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
 
MyersAAuthor Commented:
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
 
Friman001Commented:
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
 
MyersAAuthor Commented:
thanks.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 10
  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now