上次和海東兄討論了這個問題,但是他的表頭沒有線,所以用div形式實現(xiàn)了,實現(xiàn)功能顯示表格,代碼如下(后臺.cs文件只要綁定數(shù)據就可以了,字段和前臺綁定的一致就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] 下一頁
新聞熱點
疑難解答