动态显示数据的问题
我有一个页面代码大概如下:
<!-- #include file= "include/X_Index.class.aspx " -->
<%@ Import Namespace= "System.Data " %>
<%@ Import NameSpace= "System.Data.OleDb " %>
<%@ Page codePage= "936 "%>
<%
Dim x_index As X_Index = new X_Index()
%>
<Script Language= "VB " Runat= "Server ">
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Sub Page_Load(Source As Object,E As EventArgs)
'1.连接数据库
dim dbname as string
dbname=server.mappath( "bbs/data/dvBBS5.MDB ")
myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source= "&dbname )
myConnection.Open()
'5 使用DateGrid显示数据
dim sql4= "select top 6 b.boardid,b.rootid,b.announceid,b.body,b.topic from bbs1 b where 1=1 and b.parentid=0 ORDER BY b.announceID desc "
myCommand = New OleDbCommand( sql4, myConnection )
MyDataGrid.DataSource=myCommand.Executereader()
MyDataGrid.DataBind()
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 致道-中农大网络内部资源集合 </title>
<link href= "images/style1.css " rel= "stylesheet " type= "text/css " />
</head>
<body>
<div id= "login ">
<div id= "resiger ">
<form id= "form1 " name= "form1 " method= "post " action= "http://192.168.1.254/hidelogin.aspx ">
<span class= "me "> 管理系统登录 </span> 用户名: <input type= "text " name= "user " size= "8 " class= "button "> 密 码: <input type= "password " name= "psd " size= "8 " class= "button "> <input type= "submit " class= "submit " name= "NewbtAccept " value= "登录 " id= "NewbtAccept " onclick= "document.form1.submit(); " />
</form>
</div>
</div>
<div id= "top "> </div>
<div id= "content ">
<div id= "left "> </div>
<div id= "content1 ">
<div id= "bbs ">
<div id= "more "> <a href= "bbs/index.asp " target= "_blank "> <img src= "images/more.jpg " alt= " " width= "32 " height= "14 " border= "0 " /> </a> </div>
</div>
<div id= "bbs_c ">
<ASP:DataGrid id= "MyDataGrid " runat= "server ">
</asp:DataGrid>
</div>
=============================================================
可是datagrid显示的数据,不符合需求,我想要的显示如下:
<%do until rs.Eof
response.write " <li> <a href= 'bbs/dispbbs.asp?boardID= "&rs( "boardID ").value & "&RootID= "&rs( "RootID ").value & "&ID= "&rs( "announceID ").value & " ' target=_blank> " & left(replace(rs( "topic ").value,chr(10), " "),12) & "... </a> <br> </li> "
rs.movenext
loop
rs.Close()
%>
这是一段asp代码,我想要这样的显示格式。
希望各位高手帮忙,我不会vb,但是上面要求我不得不做,大家多多帮助,愿意的话加我qq:45999031,帮我指点下~~
[解决办法]
'5 使用DateGrid显示数据
dim sql4= "select top 6 b.boardid,b.rootid,b.announceid,b.body,b.topic from bbs1 b where 1=1 and b.parentid=0 ORDER BY b.announceID desc "
myCommand = New OleDbCommand( sql4, myConnection )
MyDataGrid.DataSource=myCommand.Executereader()
MyDataGrid.DataBind()
改成:
'5 使用自定义输出显示数据
dim sql4= "select top 6 b.boardid,b.rootid,b.announceid,b.body,b.topic from bbs1 b where 1=1 and b.parentid=0 ORDER BY b.announceID desc "
Dim oleadp As OleDb.OleDbDataAdapter
Dim ds As New DataSet
oleadp = New OleDb.OleDbDataAdapter(sql4, myConnection)
oleadp.Fill(ds, "bbs1 ")
dim i as integer
dim rs as datarow
for i=0 to ds.tables( "bbs1 ").rows.count-1
rs=ds.tables( "bbs1 ").rows(i)
response.write " <li> <a href= 'bbs/dispbbs.asp?boardID= "&rs( "boardID ") & "&RootID= "&rs( "RootID ") & "&ID= "&rs( "announceID ") & " ' target=_blank> " & left(replace(rs( "topic ").value,chr(10), " "),12) & "... </a> <br/> </li> "
next
[解决办法]
忘了.net 要把内容括起来:
response.write( " <li> <a href= 'bbs/dispbbs.asp?boardID= "&rs( "boardID ") & "&RootID= "&rs( "RootID ") & "&ID= "&rs( "announceID ") & " ' target=_blank> " & left(replace(rs( "topic "),chr(10), " "),12) & "... </a> <br/> </li> " )