惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
B
Blog
月光博客
月光博客
博客园 - 【当耐特】
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Jina AI
Jina AI
博客园 - Franky
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Last Week in AI
Last Week in AI
B
Blog RSS Feed
H
Help Net Security

博客园 - 阿福

TypeScript forms authentication failed the ticket supplied was invalid错误 (Windows Server 2008 + IIS 7.5) jQuery Mobile 1.1.1 RC1发布 HashSet<T> vs List<T> 不要用把无序GUID既作为主键又作为聚集索引 WCF Data Services 5.0 RTM发布 EF Power Tools Beta 2发布 Entity Framework 5性能方面的注意事项 jQuery Mobile 1.1.0 RC2发布 源码+幻灯片:学习HTML5/jQuery/ASP.NET MVC/EF Code First的绝佳资源Account at a Glance项目 使用Autofac在ASP.NET Web API上实现依赖注入 在Windows Azure上开发ASP.NET程序与在Windows Sever上有何不同 充分利用缓存来提高网站性能 ASP.NET MVC 4, ASP.NET Web API, ASP.NET Web Pages v2 (Razor)全部开源,并接受来自社区的贡献(contributions) EF5 beta2通过NuGet发布 Getting Started with HTML5 开发HTML5应用你需要了解的 WCF入门资源 jquery history plugin, url hash Run Tasks in an ASP.NET Application Domain ASP.NET 2.0: 生成Excel报表 VS 2008 hot-fix终于出来了 Images; How to create an HTTP handler to dynamically resize images and change quality. ASP.NET 2.0: Add build-in paging feature to repeater/为repeater添加内置分页功能 Tip/Trick ASP.NET 2.0: DropDownList DataBind ASP.NET 2.0: Forms Authentication Across domains Ajax类库、框架、工具包完全列表 怀旧啊 Search Box ASP.NET 2.0: Site Maps
通过客户端扩展实现固定GridView表头功能
阿福 · 2010-01-01 · via 博客园 - 阿福

当GridView单页数据较多,需要纵向滚动数据时,我们通常将gridview包裹在一个div里面,然后设置div的样式。这种方式的缺点就是滚动时GridView的表头不能固定,会被滚动出视野。网上关于固定GridView表头的实现方式有很多,但大多比较繁琐,往往需要客户端或服务器端的很多附加代码。本例的作者只通过一段客户端脚本即实现了该功能。

<style type="text/css">
    .__GridViewClass th {
        position:relative;
    }
    .__GridViewClass tr 
    {
        
        height:0px;
    }  

</style>
<script>
    function onLoad()
    {
        //Called when page first loads
        FreezeGridViewHeader("GridView1",'400px','800px',"1px solid black",null);
    }    
    
    
    function FreezeGridViewHeader(gridID,h,w,wrapperDivBorderStyle,
      wrapperDivCssClass) 
    {
        /// <summary>Used to create a fixed GridView header and allow 
        /// scrolling</summary>
        /// <param name="gridID" type="String">Client-side ID of the 
        ///  GridView control</param>
        /// <param name="h" type="Number">Height of the scrollable grid</param>
        /// <param name="w" type="Number">Width of the scrollable grid</param>
        /// <param name="wrapperDivBorderStyle" type="String">CSS style to be 
        ///  applied to the GridView's wrapper div element</param>
        /// <param name="wrapperDivCssClass" type="String">CSS class to be 
        /// applied to the GridView's wrapper div element</param>
        var grid = document.getElementById(gridID);
        if (grid != 'undefined')
        {
            grid.style.visibility = 'hidden';
            grid.className = (grid.className == null || 
              grid.className == 'undefined' ||
              grid.className == '')?'__GridViewClass':grid.className + 
              ' __GridViewClass';
            if (grid.parentNode != 'undefined') 
            {
                //Find wrapper div output by GridView
                var div = grid.parentNode;
                if (div.tagName == "DIV")
                {
                    if (this._WrapperDivCssClass != null) 
                      div.className = wrapperDivCssClass;
                    div.style.height = ((h==null)?'400px':h);
                    div.style.width = ((w==null)?'800px':w);
                    if (wrapperDivBorderStyle != null) 
                      div.style.border = wrapperDivBorderStyle; 
                    div.style.overflow = "auto";
                }
            }                
            //Find DOM TBODY element and remove first TR tag from 
            //it and add to a THEAD element instead so CSS styles
            //can be applied properly in both IE and FireFox
            var tags = grid.getElementsByTagName_r('TBODY');
            if (tags != 'undefined')
            {
                var tbody = tags[0];
                var trs = tbody.getElementsByTagName_r('TR');
                if (trs != 'undefined') 
                {
                    var headTR = tbody.removeChild(trs[0]);
                    var head = document.createElement('THEAD');
                    head.appendChild(headTR);
                    grid.insertBefore(head, grid.firstChild);
                }
                tbody.style.height = (parseInt(h) * .92) + 'px';
                tbody.style.overflowX = "hidden";
            }
            grid.style.visibility = 'visible';
        }
    }
</script>   

原文地址http://weblogs.asp.net/dwahlin/archive/2007/07/31/freeze-asp-net-gridview-headers-by-creating-client-side-extenders.aspx

补记:作者将该功能包装为一个 ajax tookit extender,可以更加方便的使用,下载。作者也介绍了该extender的具体实现步骤,可以读读,作为学习asp.net ajax toolkit extender实现的好资料,原文地址 http://weblogs.asp.net/dwahlin/archive/2007/08/08/creating-an-asp-net-ajax-toolkit-extender-control.aspx

ajax toolkit extender for freezing gridview headers