- 爱易网页
-
ASP.NET教程
- 创建固定表头、表格体滚动的DataGrid
日期:2012-05-08 浏览次数:20453 次
在使用DataGrid时,有时候需要表头表头固定、表格体的内容可以滚动,下面的代码就是实现这个功能的代码。
ShowFixedHeader.aspx
<%@ Page Language="vb" EnableViewState="False" AutoEventWireup="false" Codebehind="ShowFixedHeader.aspx.vb"
Inherits="aspxWeb.mengxianhui.com.ShowFixedHeader"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title id="lucky_elove" runat="server"></title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout" leftmargin="0">
<table align="center">
<tr>
<td>
<form id="Form1" method="post" runat="server">
<TABLE id="Table1" runat="server" cellSpacing="1" cellPadding="2" width="720" border="1"
bgcolor="#cc6633" bordercolor="#cc9966" style="FONT-SIZE:9pt;BORDER-BOTTOM:0px">
<TR align="center">
<TD colspan="2" width="430"></TD>
<TD width="190" colspan="2"></TD>
</TR>
<TR align="center">
<TD width="360" bgcolor="#66cc99"></TD>
<TD width="180" bgcolor="white"></TD>
<TD width="140" bgcolor="#99cccc"></TD>
<TD width="40" bgcolor="#009999"></TD>
</TR>
</TABLE>
<div style="BORDER:0px;PADDING:0px;MARGIN:0px;OVERFLOW:auto;WIDTH:736px;HEIGHT:200px">
<asp:DataGrid id="DataGrid1" width="720px" CellPadding="2" CellSpacing="1"
BorderColor="#cc9966" Font-Size="9pt" AlternatingItemStyle-BackColor="#6699ff"
runat="server" ShowHeader="False" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Title">
<ItemStyle Width="360px"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="CreateDate">
<ItemStyle Width="180px" HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="pid">
<ItemStyle Width="140px" HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="HitCount">
<ItemStyle Width="40px" HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
</div>
</form>
</td>
</tr>
</table>
</body>
</HTML>
ShowFixedHeader.aspx.vb