冻结标题,滚动GridView



如何冻结Asp.net网格视图标头我试图用不同的方式来做,但做不到。

我正在使用ASP 2.0和VS 2010。

有人能帮我吗?

i使用jquery floatThead

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

我必须使用一点jquery将第一行转换为thead才能工作。

以下示例:

$(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">'
    }
    );
});

如果您对Jquery满意,可以尝试Datatables Jquery插件

https://datatables.net/extensions/responsive/examples/column-control/fixedHeader.html

绑定gridview数据[c#]后

gridviewid.UseAccessibleHeader = true;
gridviewid.HeaderRow.TableSection = TableRowSection.TableHeader;

对于jquery

<script>
 function pageLoad(sender, args) {
            //Your jquery code 
            $(document).ready(function () { 
                tableGrid();
            });
            function tableGrid() { 
                $("#<%=gridviewID.ClientID%>").dataTable().fnDestroy(); 
                $("#<%=gridviewID.ClientID%>").dataTable({
                    "sPaginationType": "full_numbers",
                    "columnDefs": [{
                        "orderable": false
                    }],
                    "aaSorting": [],
                    info: false,
                    paging: true,
                    "oLanguage": { "sSearch": "Search: " },
                    mark: true,
                    dom: 'Blfrtip',
                    buttons: [], fixedHeader: true
                });
            }
        }
    </script>

注意:无论何时重新绑定数据,都可以从c#代码调用javascript函数

ScriptManager.RegisterStartupScript(this, this.GetType(), "callheader", "tableGrid();", true);

最新更新