How do I freeze an ASP.NET GridView header?

This question came up at the Public Sector Developer Conference in Anchorage, AK.  I’m trying to answer all customer questions like this via my blog so everyone has the benefit of the answer.  There are a number of ways to do it, but my favorite (because it so darn easy) is to use an ASP.NET AJAX control extender Dan Wahlin built.  I love reusable controls that make common tasks easier:).  The details and download for the extender is here.


Comments (16)

  1. Pat says:

    You can also reproduce this behavior with a simple stylesheet element…  Much easier to work with and easy to implement!

  2. Michael T says:

    As pat pointed out implementing the style portion alone works.

  3. pcs says:

    how we slide from header like excel in 2.0 asp

  4. Krirk says:

    ฺีBut every solution I found on internet that have a problem. If in your record have a dropdown list.It is a little bug for display.

  5. Aaron says:

    Krirk, I believe a z-index on the header would fix the problem of a dropdownlist showing over it.  Please let me know if this is the problem you are talking about.

    -Aaron B

  6. Ben says:

    Unless you are using IE 7 the z-index does not change the way a dropdown displays.  Basically the "select" is windowed, and does not play by the z-index rules.  I’m using IE 6 right now and the z-index does not change the way the dropdown displays over the gridview header.  I’ve been reading the IE 7 fixed this issue,  but that is not an option at my work yet.  Anyway,  the z-index does not change the dropdown displaying over the header.  FYI,  from what I have read,  the dropdown is the only control that does not play well with the z-index

  7. csharp says:

    Your solution just works if it’s in one scrollable div. If it’s in more scrollable div, it will go wrong, and I’m so headache with this problem. Can you solve it again and absolutely?


  8. rnc12345 says:

    In IE6 I have the drop down that scrolls over the header of the gridview when scrolled. Is this issue been fixed? Kindly advise.

  9. Sai Prasad says:

    paste below code in Style sheet and add this (CssClass="dropdownFix") attribute to dropdown control.



    behavior:expression( =(this.offsetParent.offsetParent.offsetParent.scrollTop-1) >(this.offsetParent.offsetTop – this.parentElement.parentElement.parentElement.firstChild.offsetHeight+1)? ‘hidden’ : ‘visible’);

    z-index: 10;


  10. Azad says:

    Nice solution……Keep it up?

  11. Ramesh Burjanroppa says:

    within grid.RowCreated try this code

    if e.Row.RowType = DataControlRowType.Header

     e.Row.Style.Add("position", "relative")

    end if

  12. Baga says:

    How to fix the problem of dropdown list overlapping the fixed columns in gridview when scrolling horizontally.

  13. bonave2008 says:

    check this ….<a href="…/freeze-scroll.htm">gridview freeze and scroll</a>