给DataGrid添加滚动条并固定表头

 
1.html

< HTML >
    
< HEAD >
        
< title > ScrollGrid </ title >
        
< meta  name ="GENERATOR"  Content ="Microsoft Visual Studio .NET 7.1" >
        
< meta  name ="CODE_LANGUAGE"  Content ="C#" >
        
< meta  name ="vs_defaultClientScript"  content ="JavaScript" >
        
< meta  name ="vs_targetSchema"  content ="http://schemas.microsoft.com/intellisense/ie5" >
        
< style >  
        .fixedHeaderTr 
{ POSITION: relative; ; TOP: expression(this.offsetParent.scrollTop) } 
        .mainDiv 
{ SCROLLBAR-FACE-COLOR: #9999ff; OVERFLOW: auto; ; WIDTH: expression(document.body.clientWidth-20); ; HEIGHT: expression((document.body.clientHeight-this.offsetTop-20>this.children[0].offsetHeight)?(this.children[0].offsetHeight+20) : (document.body.clientHeight-this.offsetTop-20)) } 
        
</ style >
    
</ HEAD >
    
< BODY  ms_positioning ="GridLayout" >
        
< form  id ="Form1"  method ="post"  runat ="server" >
            
< div  class ="mainDiv" >
                
< asp:DataGrid  id ="DataGrid1"  runat ="server"  BorderColor ="#CC9966"  BorderStyle ="None"  BorderWidth ="1px"
                    BackColor
="White"  CellPadding ="4" >
                    
< FooterStyle  ForeColor ="#330099"  BackColor ="#FFFFCC" ></ FooterStyle >
                    
< SelectedItemStyle  Font-Bold ="True"  ForeColor ="#663399"  BackColor ="#FFCC66" ></ SelectedItemStyle >
                    
< ItemStyle  ForeColor ="#330099"  BackColor ="White" ></ ItemStyle >
                    
< HeaderStyle  Font-Bold ="True"  ForeColor ="#FFFFCC"  BackColor ="#990000" ></ HeaderStyle >
                    
< PagerStyle  HorizontalAlign ="Center"  ForeColor ="#330099"  BackColor ="#FFFFCC" ></ PagerStyle >
                
</ asp:DataGrid >
            
</ div >
        
</ form >
    
</ BODY >
</ HTML >
2.cs 代码
public   class  ScrollGrid : System.Web.UI.Page
    
{
        
//记得要引用
        
//using System.Data.SqlClient;
        
//using System.IO;
        
//using System.Text.RegularExpressions;
        protected System.Web.UI.WebControls.DataGrid DataGrid1;
    
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            DataBind();
        }


        
Render

        
DataBind

        
GetDataSet        

        
Web Form Designer generated code
    }
3.源代码下载 /Files/singlepine/WebApplication1.rar
代码里面的数据库及web.config要自己修改。  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值