views:

376

answers:

3

Hello,

I have a dataview with around 2000 rows. At page load I want to bind the dataview to an object datagrid :

    dataGrid.DataSource = dv;
    dataGrid.DataBind();

However the time response is very high (a couple of minutes). What can I do to make it faster ? Or at least can I not freeeze the client ?

A: 

Check how long it takes to return data from the dB. If it isn't too long, the problem is probably down to the page attempting to render 2000 rows.

If so, paging will speed things up.

adrianos
Paging with a datagrid isn't really a good idea with large datasets because the query will run subsequent times each time the page is changed and the grid will dispose of the records that aren't needed.
Achilles
It may not be a perfect approach but it answer the original poster's question - making it faster. Get it working, then figure out the best approach.
adrianos
I'd argue the best approach is to avoid having a 2000 row view of data. Filter the view using parameters would make for a better user experience AND optimize the page loading.
Achilles
The dbrequest is fast however users want all the data displayed in the same page... At least, can I make the rows to be displayed continuously when they are commit (that is to say, the scroll bar becomes more and more big...)
Toto
Toto, they want all 2000 rows displayed on the same page?
adrianos
I'd explain to the users that what they want is crazy...there is no usefulness to having all 2000 records on the screen. They will only come back to you and ask you to change it.
Achilles
Yes they want to display all the rows on the same page...
Toto
Are all the columns necessary? If not, try cutting down on the ones you display until you are showing the absolute minimum.If your users insist that all columns are necessary, as is 2000 rows, then they will just have to accept the long wait. If all you need to do is show data, you might want to try a repeater instead of a gridview - I think it renders faster. Good luck.
adrianos
Ok, thx for your help. I am going to try to convince users to change their requirements.
Toto
Storing the 2000+ records in session will make paging less DB intensive but possibly tax your server if you have a lot of users with many sessions.
Kelsey
A: 

I'd reduce the number of items you are bring back in your query with some type of default filter. That much data on the screen is USUALLY going to make for a bad user experience anyway and the default filter would speed up the rendering of the page. If the user asks for 2000 rows of data then let them have it...but I'd avoid doing paging with the datagrid because the paging discards the records that aren't in the current "page" after it executes the query and brings back all 2000 records. So if set the paging to 20 items, the query will still bring back all 2000 records and the grid will remove the other 1980 records each time the user asks for a new page...

Achilles
+2  A: 

Check your query first. Once you have it as fast as you can get it (including possibly pre-caching data nightly in a temp table or something) then move to the ASP.NET code and make that faster.

Turn off viewstate for your grid if you can. The viewstate will increase your page size dramatically. Part of your problem will be just serving up the MB's of raw HTML and viewstate and then rendering it.

Steps I would take:

  1. Turn off viewstate for the grid
  2. If you are using templates in your columns, try and trim them down by combining controls to reduce the amount of duplicate binding that is occuring.
  3. Use literal controls in your templates when possible (significantly lighter than labels)
  4. Pull out all the styling and make sure you you use css to bring down the page size as well.
  5. If your rows have any javascript, consider removing any inline scripts and applying it once the page loads via Jquery or some other method.
  6. Think about paging your data

You can get the 2k+ records to work on one page but you will have to make things very tight to do so.

Last resort, get rid of the grid and just use a literal control and output raw, clean, tight html directly to it. Make sure to turn off viewstate for the literal control in this case as well.

Kelsey
Ok, I will try the four steps.
Toto
Added 2 more steps for you try as well.
Kelsey