ASP.NET HTML 控件 数据库链接 - 绑定一个 Repeater 控件

asp.net html 控件 数据库链接 - 绑定一个 repeater 控件

<%@ import namespace="system.data.oledb" %>

<script  runat="server">
sub page_load
dim dbconn,sql,dbcomm,dbread
dbconn=new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("/db/northwind.mdb"))
dbconn.open()
sql="select * from customers"
dbcomm=new oledbcommand(sql,dbconn)
dbread=dbcomm.executereader()
customers.datasource=dbread
customers.databind()
dbread.close()
dbconn.close()
end sub
</script>


<!doctype html>
<html>
<body>

<form runat="server">
<asp:repeater id="customers" runat="server">

<headertemplate>
<table border="1" width="100%">
<tr bgcolor="#b0c4de">
<th>companyname</th>
<th>contactname</th>
<th>address</th>
<th>city</th>
</tr>
</headertemplate>

<itemtemplate>
<tr bgcolor="#f0f0f0">
<td><%#container.dataitem("companyname")%> </td>
<td><%#container.dataitem("contactname")%> </td>
<td><%#container.dataitem("address")%> </td>
<td><%#container.dataitem("city")%> </td>
</tr>
</itemtemplate>

<footertemplate>
</table>
</footertemplate>

</asp:repeater>
</form>

</body>
</html>
相关文章