View State vs Server Load with Binding multiple gridviews in Asp.Net - asp.net

There are 3 grid views.(one is filtered with search functionality and other two are just data bound)
View state disabled for all the three to lessen server resources.
Problem:
after performing filtering on 1st grid, remaining two are loosing its bound data.
which are the following are best alternatives?
Bind remaining two grids manually for every page load.
just enable view state independently for the remaining two grids.
any other suggestions apart from 1 and 2.

Related

ASP.NET C# Gridview with dropdown lists per row leads to slow processing page

I have a Gridview where tens or hundreds of rows can be populated from a database. This is all good and well, however the first column of each row contains a dropdown list that can load hundreds of options. The user can select one of the options (search the dropdown list) and then save the selection (all the edited rows on the page).
All works good and well however it creates a VERY slow and heavy page (as each row has this dropdown list with hundreds of options).
I cannot deploy paging and limit the number of rows to 10 for example as the users like that Datatables is used and they can search for their specific row using the search option that Datatables provides (all the data loaded into page) rather than some bespoke slow search that will only search the loaded page of data for example.
I have been wrecking my head for days now to find a solution that would suit this need, the functionality of Datatables, the dropdown for each row to allow the user to select while not restricting the number of rows loaded for the user experience.
This all with the ability for the page to load in a decent amount of time and be user friendly. Sounds like a catch 22 and am open to any suggestions.
Is there any way for example to have one javascript object with all the dropdown options and then reference it (duplicate it) for each row without actually loading the dropdown for each row on Databound?
Much appreciated.

Grid loading too slow with out pagination

We have developed Asp.net web application. and we are using asp.net gridview to display the records and edit.
here we have 5000 rows and 23 columns in single grid. it is taking long time for binding. our client refuse the pagination option. how to make the binding faster with 5000 to 7000 records.
Please Advise.
Thanks
Mayil.M
Where is your data come from? Is it database or other external resource?
You can use caching so you don't load the whole dataset from the external resource but from the memory. Please note this solution will not work if your data changes often.
Another approach would be to use some kind of partial loading mechanism using for example Ajax. This will however require changing approach as I am not sure the grid view control supports this. You would have to create custom control and then make sequential requests (using for example Ajax) for smaller chunks (eg. 200 records) of data and display them. Eventually you will have complete set but the data will be available faster.
Finally you can combine both, to make it even faster.
You should implement your own paging mechanism. The problem is that DataBind retrieves all 7000 records (although only i.e. 20 is displayed/rendered). Create for example a stored procedure that will fetch only selected range of records (if you are on Page 2 you need to display only record id > 20 and <= 40 - considering that your pagesize is 20). Use SQL server CTE to get the row number (on SQL Server side) and features like BETWEEN. This stored procedure would return only those records which you really need to. Then change your grid view to get the data from this stored procedure.
You can load data on scroll like facebook wall.

Optimizing performance of large ASP.NET applications

I'm building a asp.net web application with lots and lots of controls and huge volumes of data. My application is very slow and it is taking a large amount of time to load the data into the .net controls like grid, tree view etc. I also have some ajaxified pages and controls in my application. I want to reduce the page load time in each postbacks.
What are the standards/best practices to be followed while developing large asp.net applications?
Thank you.
NLV
Cache certain data, either in the application or in the database (thus breaking normalization but it's okay)
Retrieve the minimum subset of data you really need. Don't pull 10000 records from the database into a grid to only display 50. Query for exactly 50.
Mimimize the amount of server controls and dynamic markup creation. Replace what you can with passive HTML elements.
Switch off the view state, which can potentially expand pages to many megabytes in size. Pull the data from the database on each request (in combination with caching strategies).
You Can use JQuery to retreive the data from database which is much better than using ajax. Check this http://www.codeproject.com/KB/webservices/JsonWebServiceJQuery.aspx

With 2 nested gridviews with large data sets each what's the most optimized way to implement

Say I have 2 tables in a database, each with 100,000's of rows in detail and 10,000's of rows in the master 5 columns each, properly indexed and related. I want to have master/detail nested gridviews. What's the fastest architecture I could design in .net to do this? The largest result set on the master could be in the thousands (usually in the tens though) and the detail per records could be in the hundreds (usually in the single digits though). I'd like to be able to do a display all masters if possible.
The bottom line: bind to DataReaders, use Repeaters instead of GridViews, and turn off ViewState.
The design you're proposing is going to be pretty hard on your users (thousands of records, yikes), but you probably already know that.
If this is just for display and you want the absolute fastest architecture for Asp.Net, you should obtain an IDataReader for each data segment (master and child), sorted such that you can manually match child records while reading both resultsets in a forward-only fashion. (See Scott Mitchell's Why I don't Use DataSets in my ASP.NET Applications for some details about DataReader performance - as long as you aren't optimizing prematurely, it's quite good advice.)
Instead of using a GridView, I'd use a Repeater which has less overhead and lets you write more compact HTML (for a smaller payload to the client): bind the master IDataReader to that repeater. (I'm not sure whether you meant the GridView control, or just a conceptual grid - the basic architecture would be the same for a GridView)
Then add a handler to the Repeater.ItemDataBound that checks if the child data reader's current record matches. If it does, manually render your detail data for that master record.
Finally, you should also turn ViewState off, at least for the Repeater (preferably for as much of the page as possible), again so that the HTML payload is smaller.
If you're totally committed to nested GridViews, particularly to using a GridView to render the detail data, it's going to hurt the performance one way or another, because you'll have to either make many more database calls (to obtain discrete resultsets you can bind to) or you'll have to massage the detail data into an intermediary container.

How to unit test a grid with paging

A common web UI design is to display a sortable grid (GridView, ListView, DataGrid) with paging. That is, the user can click on any column header to cause the records to be sorted in ascending or descending order on that column's data. And, the user can navigate among the pages of, say, 10 records at a time.
There may be millions of database
records that could potentially be
displayed on the grid.
There are many possible filters that
could be applied to the data
selection. The displayed records
might apply to the current user, or
to a date range, or to a customer,
department, product, order.
The user can sort the displayed
records on any column, and they can
navigate among pages.
How would you write a unit test(s) to confirm that the selected records are the correct records, for this filter, this page, and this sort order?
You will have to
decouple the filtering, sorting from the actual source so that you can mock the datasource
and test if the logic returns the correct records.
decouple the paging logic from the grid so that you can test if the paging gives the right indexes back.
That way you can test the filtering and the paging logic in separate units.
Next you could also use a automatic webtest to test the complete stuff (integration test).

Resources