How to get gridview to change pages faster - c#

GridView in my ASP.NET application is working very slowly when changing pages. I know that this is most probably caused by a lot of data being pooled out of database each time page is updated but I don’t know how to fix this since I’m not to ASP.NET.
My current configuration is GridView with ObjectDateSource and paging enabled. I don’t have any code behind or anything similar. ObjectDataSource is bined to typed data set.

You are correct about the cause of this – it’s the fact that you have to get all the data from database even if you only want to display one small part. For example, you retrieve 5000 rows from DB only to display 15 rows in current page.
Solution for this is implementing custom paging.
In order to get this to work with your current configuration you’ll need to update your current select method to accept the starting index and maximum number of rows input parameters and also update following properties in your grid view
“StartRowIndexParameterName”, “MaximumRowsParameterName”, “SelectCountMethod”.
Here is a great article that covers what you need but there are also a lot of topics here on StackOverflow that cover this topic.

I found the same problem and implemented a custom gridview which is now opensource, you can find it here https://github.com/vcliment89/GridViewEX. You don't need to implement all the gridview but there's an example of a custom pager on the demo project.

Related

repeater with custom filters in asp.net

I have repeater control in which i am binding data from sql server database, Now i have number of records showing on my page but i want that i can filter my records according to dropdown selected. I need 4-5 dropdowns control thats depend on my need and i don't want my page to refresh while filtering.
Below is the example, this website using checkboxes too but i need only dropdowns...
http://www.phonearena.com/phones/full#/phones/full/
Give me any idea how to start, i think ajax is the thing i need. Suggest some examples if you have.
Ajax is the right solution.
Personally i suggest you jquerytemplate and ajax call few row code to achive your goal you may find more info here Load JSON data using the dropdown menu and refresh the div area with the new results in a web site
It is a good point to start and you can make more stuff with this logic :) really simple and fluid code :)
I would suggest you to use a client-side framework (so in JavaScript) like AngularJS, BackboneJS or KnockoutJS. They all provide ways to work with collections in JavaScript (like filtering in this case). You won't need Ajax excepted for the first load or if you want to do some paging. And because it's all client-side it will be far more fluid than re-downloading at every criteria change.

Display records page wise using ASP.NET with C#

I have created web page that retrieves data from MS SQL database and display it to the user in well formatted manner. Data retrieved depend upon criteria selected by the user. But sometimes data retrieved is very large. I want to display records to the user page wise, i.e. 100 records on first page and next 100 records displayed when user clicks next button. This means only 100 records should be retrieved when user first select search criteria, next 100 records retrieved when he clicks next button and so on, as to reduce data transferred from server to client.
Please suggest me how to achieve this as soon as possible. Thanks in advance.
What you are looking for is called paging.
This can be done a million ways. You mention jquery, javascript and asp.net. For displaying purpose that is quite all righ but for good performance you want to make sure that the actual selection of the page has to be done at the backend.
One approach is this:
http://msdn.microsoft.com/en-us/library/aa479347.aspx This is not jquery but it shows a way to do it.
You can use jqGrid or DataTables. Both are very popular grids
Ask user to set there criteria and then render the grid according to that.
If you want simple fast and way then think in using jQuery plugins like these
jpaging OR datatables.
you should search for design pattern for this.
kindly look at this Easily build powerful client-side AJAX paging, using jQuery
Your use of both asp.net and C# makes me (probably because I am partial to it) think "WebMatrix". If, indeed you are using WebMatrix, check out its Grid Helper. However, be warned that this method can generate some very serious overhead for your html page (by that I mean that if you query 1,000 rows and only use 100 per page, it will retrieve all 1,000, use 100, and waste the other 900). Also, using the WebGrid generates the results in a table, which may not be your preferred style.
Alternatively (still thinking "WebMatrix"), you could use this article here (this is my preferred method): http://www.mikesdotnetting.com/Article/150/Web-Pages-Efficient-Paging-Without-The-WebGrid
Don't worry, that article is explained with EXCELLENT brevity and accuracy (and explained better than I could, so I leave it to Mike to vicariously answer that one).

Is there a ready-made data table view library with paging/filtering/sorting?

I'm building a system in MVC that has a lot of heterogeneous data to be displayed: Customers, logs, etc.
I'm finding that I'm building the same view over and over again in different forms:
Header row (with sorting links)
Filter row (drop-downs, date pickers, etc.)
Data
Paging row
Naturally the abstractor in me is shouting "Build a generic data view factory!", as well it should. However, before I disappear up my own abstracting bottom, has this work already been done elsewhere?
The only option I can currently find is MVCContrib.Grid, which doesn't seem to handle the rendering of filters (although it has allowances for extending the renderer). Is this the only option?
As one may expect a question similar to your has already been done...years ago. So here: grid controls for ASP.NET MVC? you can find a list available data grids, that has been updated in the years. I recommend that you, once and for all, give a look to all of them, so in the furure you may choose the more adequate to your needs. There is no better grid, but each of them has advantages and disadvantages.
Yes, I could recommend this jQuery plugin
http://datatables.net/
My Choice would be between
datatables.net (Already mentioned)
jqGrid (http://www.trirand.net/demoaspnetmvc.aspx)
I've foud the datatables easier to use at first, but finally I've used jqGrid as I've foud it more powerfull.
I've used both KendoUI and jqGrid successfully. jqGrid is a light-weight and less expensive solution if all you are looking for is a grid. One of the things I liked about jqGrid aside from its easy integration with knockout was it's ability to edit data in table cells as well as creating a "edit view" in which the data is edited in a form-type view with labels beside edit widgets.
That said, it sounds like you might be looking for more than a grid, and if so you should also look at using Html helpers to generate the constituant parts (header w/filter, data rows, paging, etc). This would give you ultimate flexibility over where the different parts are rendered on the page. Maybe you want to put the paging controls twice on the page at the top and bottom; maybe you want to put the filtering into a modal dialog box. The ability to simply go:
#Html.FilterControlsFor(Model.PhoneBookUsers)
someplace (or someplaces) on a page and have the helper deal with all of the details is pretty powerful juju.
Flexigrid - nice table plugin, but it is only ui table you should provide appropriative server side processing for selection and filtering data.
KendoUI any day. Theres a ASP.NET wrapper but it's quite expensive. But the jQuery lib is definitly the best out there.

ASP.NET MVC Selectable Tree/Grid/Search Data View

I'm working on a web app in ASP.NET MVC 3 using the Razor HTML 5 engine and C#. The client wants something pretty complex and I would like to know if there is any examples out on the web that might show me how to begin setting this up. Here's what they are looking for:
I have a very large SQL database (25,000 rows). They want to be able to select the data using three different views on the same page.
The first will be a tree and using similarities in certain columns of the table will be how the tree is broken in to sections.
The second will be a grid. This will be just one entire list of the everything in the database that you can scroll through. Of course there has to be some sort of virtual scrolling because loading 25,000 rows rather quickly isn't going to happen.
The third will be a search box where you can type in the code and select it that way.
All three of these need to be linked so that when you type a code in the search box it will select it in the grid and in the tree. If you select it in the tree then it will be selected in the grid, and if you select it in the grid then it will be selected in the tree.
They also want me to remember the last selection when you navigate away and be able to type a code n on a different page and go directly to this page with the item you typed selected. Therefore, I need to be able to use MVC's capabilities to establish a hyper link for every item in the list (I assume that would be the way to do this)
This is honestly the first time I've worked with ASP.net MVC and I feel like I may have bitten off more than I can chew with this project so any help would be greatly appreciated!
They would rather it if I didn't need to include any extra dll's so if there is a way to do this without third party tools that would be even better, but at this point I'm just looking for anything.
A few random ideas/thoughts about this:
This is kind of a big project as your first MVC app - hopefully you have some experience with HTML/Javascript/jQuery since it's going to require a fair amount of glue code to make everything work together. There is no "here, do this" solution.
There are a bunch of different free/open source projects for treeviews and grids. I've used jqGrid for a number of projects - it works well. It has a decent API and is fairly configurable (although it may take some digging to find the example code you need).
For a treeview, you can try jsTree. I haven't worked with it, though.
I'd suggest starting with just the treeview, or just the grid and get it working first. Then add the other control and get it working. Then add the search. Finally, I'd work on getting everything to work together.
To handle navigating to a specific selection, you can pull information off the query string from Javascript.
Realize that most of this is going to be happening in Javascript on the client side, not much server side.

Poor performance with big tables on explorer 7

I have a table with 2K+ rows in it.
In chrome, firefox and IE8,9 it works fine, but in IE 7 the user will have to wait 30s or so...
The table is built using .NET's GridView.
According to some reading I've made, setting the width of the cells myself, rather than let the browser calculate it for each TD is better approach, and that what I've done...
What can I do to improve the loading time of the page?
Thanks in advance.
what you should do anyway is add paging and avoid showing 2K records on the same page inside a Grid. This should be done anyway also on the database access level, pointless to query all those rows out of the database, transport them to the web server and render them in the same page. Set up grid paging and limit the page size to something smaller usually between 20 to 100 depends on the context.
For a step by steg guide on how to enable paging, see here:
GridView Examples for ASP.NET 2.0: Paging and Sorting the GridView's Data
Like what Davide suggested, showing 2k rows is alot, and either cutting down that number or using something like http://www.datatables.net/ that can split it into multiple pages or all on one page but only loads the pages you can see.
It also supports async loading, so the users get a mucher better experience

Categories

Resources