ASP.NET HTML 控件 数据库链接 - 绑定一个 DataList 控件
asp.net html 控件 数据库链接 - 绑定一个 datalist 控件
<%@ 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:datalist
id="customers"
runat="server"
cellpadding="2"
cellspacing="2"
borderstyle="inset"
backcolor="#e8e8e8"
width="100%"
headerstyle-font-name="verdana"
headerstyle-font-size="12pt"
headerstyle-horizontalalign="center"
headerstyle-font-bold="true"
itemstyle-backcolor="#778899"
itemstyle-forecolor="#ffffff"
footerstyle-font-size="9pt"
footerstyle-font-italic="true">
<headertemplate>
customers table
</headertemplate>
<itemtemplate>
<%#container.dataitem("companyname")%> in
<%#container.dataitem("address")%>, <%#container.dataitem("city")%>
</itemtemplate>
<footertemplate>
source: northwind database
</footertemplate>
</asp:datalist>
</form>
</body>
</html>
<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:datalist
id="customers"
runat="server"
cellpadding="2"
cellspacing="2"
borderstyle="inset"
backcolor="#e8e8e8"
width="100%"
headerstyle-font-name="verdana"
headerstyle-font-size="12pt"
headerstyle-horizontalalign="center"
headerstyle-font-bold="true"
itemstyle-backcolor="#778899"
itemstyle-forecolor="#ffffff"
footerstyle-font-size="9pt"
footerstyle-font-italic="true">
<headertemplate>
customers table
</headertemplate>
<itemtemplate>
<%#container.dataitem("companyname")%> in
<%#container.dataitem("address")%>, <%#container.dataitem("city")%>
</itemtemplate>
<footertemplate>
source: northwind database
</footertemplate>
</asp:datalist>
</form>
</body>
</html>
相关文章
- ASP.NET 教程
- ASP.NET Web Pages 文件夹
- ASP.NET Web Pages Email
- ASP.NET WebPages 帮助器参考手册
- ASP.NET Razor VB 循环和数组
- ASP.NET Razor VB 逻辑
- ASP.NET MVC 安全
- ASP.NET MVC 参考手册
- ASP.NET 数据库连接
- ASP.NET CalendarDay 控件
- ASP.NET Literal 控件
- WebSecurity CreateAccount 方法
- WebSecurity GetUserId 方法
- WebSecurity RequireRoles 方法
- HTML InputHidden
- HTML Table
- AdRotator
- ASP.NET HTML 控件 Calendar 3
- ASP.NET HTML 控件 Textbox 2
- ASP.NET HTML 控件 RangeValidator