上次和海东兄讨论了这个问题,但是他的表头没有线,所以用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>
共2页: 上一页 1 [2] 下一页
新闻热点
疑难解答