How to freeze GridView header?

前端 未结 7 785
一生所求
一生所求 2020-12-10 04:54

As in a title, does anyone know how to freeze GridView header in ASP.NET ?

相关标签:
7条回答
  • 2020-12-10 05:14

    You can do it in the css

    Freeze Header: 1. Define class .Freezing in Stylesheet:

    .Freezing
    {
       position:relative ;
       top:expression(this.offsetParent.scrollTop);
       z-index: 10;
    }   
    

    2.Assign Datagrid Header's cssClass to Freezing

    0 讨论(0)
  • 2020-12-10 05:20

    I think I have solution of this. please see below javascript code

    <script type="text/javascript" language="javascript">
        var orgTop = 0;
        $(document).scroll(function () {
            var id = $("tr:.header").get(0);
            var offset = $(id).offset();
            var elPosition = $(id).position();
            var elWidth = $(id).width();
            var elHeight = $(id).height();
            if (orgTop == 0) {
                orgTop = elPosition.top;
            }
            if ($(window).scrollTop() <= orgTop) {
                id.style.position = 'relative';
                id.style.top = 'auto';
                id.style.width = 'auto';
                id.style.height = 'auto';
            }
            else {
                id.style.position = 'absolute';
                id.style.top = $(window).scrollTop() + 'px';
                id.style.width = elWidth + 'px';
                id.style.height = elHeight + 'px';
    
            }
        });
    </script>
    

    where .header is the css class of your Grid header.

    Just add this script on the page and replace header with the css class name you have used for your header.

    0 讨论(0)
  • 2020-12-10 05:21

    You may try the following sample

    Freeze GridView Columns

    0 讨论(0)
  • 2020-12-10 05:25

    I too faced a similar issue while developing in the web applications in Asp.Net 2.0 / 3.5.

    One fine day, I came across IdeaSparks ASP.NET CoolControls. It helps to display fix column headers, footer and pager.

    I used them personally and I really loved it!

    To check the control click here : IdeaSparks ASP.NET CoolControls

    Hope this helps!

    0 讨论(0)
  • 2020-12-10 05:29

    Try this open-source project for ASP.NET. It extends GridView to provide fixed header, footer and pager and resizable column width. Works well in IE 6/7/8, Firefox 3.0/3.5, Chrome and Safari.

    http://johnsobrepena.blogspot.com/2009/09/extending-aspnet-gridview-for-fixed.html

    0 讨论(0)
  • 2020-12-10 05:35

    Give this a try should solve the problem http://www.codeproject.com/KB/webforms/FreezePaneDatagrid.aspx

    0 讨论(0)
提交回复
热议问题