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:

Code (csharp)

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.

This entry was posted on Thursday, June 28th, 2007 at 1:13 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “ASP.Net Gridview Progressive HTML Rendering”

  1. MB Says:

    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?

  2. Melinda Reid Says:

    q8ajqwrqfhxnherk

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>