开发者

Asp.net binding big dataview to DataGrid

I have a dataview with around 2000 rows. At page load I wa开发者_如何学JAVAnt 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 ?


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.


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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜