上次和海东兄讨论了这个问题,但是他的表头没有线,所以用Div形式实现了,实现功能显示表格,代码如下(后台.cs文件只要绑定数据就可以了,字段和前台绑定的一致就OK了,在此不加赘述):
<%@ Page language="c#" Codebehind="dg1.aspx.cs" AutoEventWireup="false" Inherits="netLearn.dg1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>dg1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="javascript">
function window.onload()
{
var dg = document.getElementById('DataGrid1');
var strHTML = "";
for( var i=1; i<dg.rows.length;i++)
{
strHTML += dg.rows[i].cells[0].innerHTML;
}
dg.rows[1].cells[0].innerHTML = "<div id='dgContent' style='height:250px;overflow-y:scroll'>" + strHTML + "</div>";
for( var i=dg.rows.length-1; i>1;i--)
{
dg.deleteRow(i);
}
}
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:datagrid id="DataGrid1" runat="server" Width="576px" Height="192px" AutoGenerateColumns="False"
BorderWidth="0px" CellPadding="0">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<table cellpadding="2" cellspacing="1" bgcolor="PaleTurquoise" width="100%">
<tr>
<th bgcolor="#006699" width="25%" align="center" style="color:#ffffff">
序号</td>
<th bgcolor="#006699" width="25%" align="center" style="color:#ffffff">
ID号</td>
<th bgcolor="#006699" width="25%" align="center" style="color:#ffffff">
姓名</td>
<th bgcolor="#006699" width="25%" align="center" style="color:#ffffff">
年龄</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table cellpadding="2" cellspacing="1" bgcolor="PaleTurquoise" width="100%">
<tr>
<td bgcolor="LightSkyBlue" width="25%" style="padding-left:10px;"><%#Container.ItemIndex+1%></td>
<td bgcolor="LightSkyBlue" width="25%" style="padding-left:10px;"><%#DataBinder.Eval(Container.DataItem,"ID")%></td>
<td bgcolor="LightSkyBlue" width="25%" style="padding-left:10px;"><%#DataBinder.Eval(Container.DataItem,"Name")%></td>
<td bgcolor="LightSkyBlue" width="23%" style="padding-left:10px;"><%#DataBinder.Eval(Container.DataItem,"Age")%></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></FONT></form>
</body>
</HTML>