gaoxiang

专注于.NET技术

博客园 首页 新随笔 联系 订阅 管理

 
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要自己修改。
posted on 2005-10-30 18:12 小山 阅读(839) 评论(4)  编辑 收藏 收藏至365Key 所属分类: DataGrid

Feedback

# re: 给DataGrid添加滚动条并固定表头 2005-12-05 19:39 ChengKing
多谢!
如果附加: *.rar下载链接提供下载会更好  回复
  

# re: 给DataGrid添加滚动条并固定表头 2005-12-05 20:34 小山
已提供源代码下载,代码里面的数据库及web.config要自己修改。  回复
  

# re: 给DataGrid添加滚动条并固定表头 2005-12-05 22:24 devuser
和我的差不多.
http://devuser.cnblogs.com/archive/2005/10/26/262663.html
可惜我的没有把表头加样式那一段render,但DIV已经嵌套在里面.
结合一下就更完美了.  回复
  

# re: 给DataGrid添加滚动条并固定表头 2005-12-06 08:33 Qqwwee_Com
不赞成Render这个函数里面的做法。

设置header的class用下面就可以了。
<HeaderStyle CssClass="fixedHeaderTr" ></HeaderStyle>  回复
posted on 2006-03-10 10:27  S孤单一吻S  阅读(1612)  评论(0)    收藏  举报