ASP.Net Gridview Progressive HTML Rendering
Here’s a bit of a change of topic, let’s talk about gridviews in ASP.Net.
I find them quite convenient, but one thing that bothers me sometimes is that if I have a huge table (reports and such), I have to wait for the entire thing to be stored in the buffer before the user can see anything. So, of course, I had to go ahead and do something about it.
Basically, the way I went about getting the gridview to show up progressively was my creating my own gridview and gridviewrow to handle the rendering of each row. Here’s the code:
namespace Neaveru.Controls
{
public class NeaveruGridView : GridView
{
//We just want to override one method, CreateRow
//We just have it rendering our own gridviewrow, instead of the normal one
protected override GridViewRow CreateRow(int rowIndex, int dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState)
{
return new NeaveruGridViewRow(rowIndex, dataSourceIndex, rowType, rowState);
}
}
//The gridviewrow that does the magic
public class NeaveruGridViewRow : GridViewRow
{
public NeaveruGridViewRow(int rowIndex, int dataItemIndex,
DataControlRowType rowType, DataControlRowState rowState) :
base(rowIndex, dataItemIndex, rowType, rowState) {}
//We just call the base render and flush out the page buffer
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Page.Response.Flush();
}
}
}
That’s all!
Now you can use the control in place of the regular GridView and you’ve got progressive gridview rendering.
August 18th, 2008 at 9:42 am
Thanks for posting a solution for this. Unfortunately I can’t seem to make it work. The page renders exactly the same. I even tried adding table-layout:fixed to the gridview table style attributes with no luck.
Any suggestions?
November 12th, 2008 at 7:17 pm
q8ajqwrqfhxnherk