我家的小院原文:关于asp:数据库查询并显示的问题

来源:百度文库 编辑:高考问答 时间:2024/05/04 19:47:57
前提:
asp的网页,使用vbscript, .mdb数据库,ISS服务器。
我用sql语言查询数据库后,在网页上显示查询的表。其中有3点没能解决:
1、表格如何隔行现实不同的背景色?
2、鼠标在表格的每一行上时,该行背景色改变为绿色?
3、在表格中的其中一列,每个记录都带有超链接,且每个超链接都不同。(超链接来自查询的数据库。)
想要达到的效果,可以参看:
http://www.444.com.cn/plant/

这个有什么难的,你把你要查询的代码(表,字段)发出来,我来弄..

我这里有个简单的查询,你换一下参数就可以用的..
<table width="95%" border="0" cellpadding="0" cellspacing="0" class="190">
<%selectsql="select top 5 * from article_content order by dat desc"
dbnews.getrecordset(selectsql)
i=1
do while not dbnews.rs.eof
If i Mod 2 = 0 Then
bg="#666666"
Else
bg="#ff0000"
End If
%>
<tr bgcolor="<%=bg%>" onmouseover="this.bgcolor=red" onmouserout="this.bgcolor=blue">
<td width="78%">·<a href="../admin/newsfile/<%=dbnews.rs("one_wjm")%>" target="_blank"><%=str.leftstring(dbnews.rs("title"),11)%></a></td>
</tr>
<tr>
<td height="1" background="images/line.gif"></td>
</tr>
<%
i=i+1
dbnews.rs.movenext
loop%>
</table>

其实不难的:
1.每行不同背景颜色。加如一个变量表示当前是奇数行还是偶数行。
2.用JAVASCRIPT来实现鼠标移动后表格的效果。
3.直接ASP输出读取的连接。

例如:
...
<style>
.htd1 {background-color:green}
.htd1 {}
</style>
...
i=0
do while not rs.eof
if i=0 then
response.write("<tr bgcolor='#ffffff'") '设置背景颜色,注意这里 tr 不完整没有
i=1
else
response.write("<tr bgcolor="#eeeeee"")
i=0
end if '每行不同背景颜色实现
response.write ( "onMouseOver=this.className=htd1' onmouseout='this.className=htd' >") 'tr输出完,实现了鼠标移动效果

response.write ("<td><a href='...?id=" &rs("id") &">" &rs("Name") &"</a></td>") '不同的链接
response.write ("</tr>")
rs.movenext
loop

这估计没人能帮上你忙,这得写几个asp文件的。

您可以到一些专门的论坛上面把您编好的asp代码贴上,然后求高手给予指正。

希望早日解决。

<script language=javascript>
function setPointer(theRow, thePointerColor)
{
if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) ==

'undefined') {
return false;
}

var row_cells_cnt = theRow.cells.length;
for (var c = 0; c < row_cells_cnt; c++) {
theRow.cells[c].bgColor = thePointerColor;
}

return true;
}
</script>

</head>
<link href="/DefaultSkin.css" rel="stylesheet" type="text/css">
<TABLE cellSpacing=1 cellPadding=4 width="100%" align=center bgColor=#e2e2e2

border=0>

<TR bgColor=#f6f6f6 onmouseover="setPointer(this, '#96C778')"

onmouseout="setPointer(this, '#f6f6f6')">
<td>第一行</td><td>角。。</td>
</TR>
<TR bgColor=#ffffff onmouseover="setPointer(this, '#96C778')"

onmouseout="setPointer(this, '#f6f6f6')">
<td>第二行</td><td>角。。</td>
</TR>
</table>
按以上代码设计你的输出文件。就能实现鼠标移到该行变色。
输出文件时,设1个变量,当该变量为偶数时<TR bgColor=#ffffff
为奇数时<TR bgColor=#f6f6f6
就能实现每行不同的颜色。
在你要插入链接的地方用ASP write出链接