Freeze the header, scroll the GridView

asp.netgridview

How to freeze an Asp.net gridview header? I am trying to do it in different ways, but not able to.

I am using ASP 2.0 and VS 2010.

Can any one help me?

Best Answer

i use jquery floatThead

http://mkoryak.github.io/floatThead/#intro

i had to use a bit of jquery to convert to first row to a thead for it to work.

example below:

$(document).ready(function () {
    var $theadCols = $("#ContentPlaceHolder1_grdCashflow  tr:first-child"),
        $table = $("#ContentPlaceHolder1_grdCashflow");

    // create thead and append <th> columns
    $table.prepend("<thead/>");
    $table.find("thead").append($theadCols);

    // init stickyHeader
    $table.floatThead();

    //$table = $("#ContentPlaceHolder1_grdCashflow");
    $table.dataTable(
    {
        "paging": false,
        "ordering": false,
        "dom":'<"top"fi>rt<"bottom"><"clear">'
    }
    );
});