/*
文章出处:http://www.aspcool.com 转载请注明,谢谢!
*/列表,数据和数据棒定
asp+ 给我们提供了一套数据表格和数据列表的控件。这些控件可以帮助我们定制我们ui(user interface 用户界面)而不去考虑一种数据库或者其他的数据库。例如:在下面的例子中,我们将要介绍一下<asp:datagrid runat=server>控件是怎么样通过sql 语句给我们提供数据的
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sql" %>
<html>
<head>
<link rel="stylesheet"href="intro.css">
</head>
<script language="vb" runat=server>
sub submitbtn_click(sender as object, e as eventargs)
dim ds as dataset
dim myconnection as sqlconnection
dim mycommand as sqldatasetcommand
以下是数据库联结
myconnection = new sqlconnection("server=localhost;uid=sa;pwd=;database=pubs")
mycommand = new sqldatasetcommand("select * from titles where type=" + category.selecteditem.value + "", myconnection)
ds = new dataset()
mycommand.filldataset(ds, "titles")
mylist.datasource = ds.tables("titles").defaultview
mylist.databind()
end sub
</script>
<body>
<center>
<form action="intro75.aspx" method="post" runat="server">
<asp:adrotator advertisementfile="ads.xml" bordercolor="black" borderwidth=1 runat="server"/>
<h3> name: <asp:textbox id="name" runat="server"/>
category: <asp:dropdownlist id="category" runat=server>
<asp:listitem >psychology</asp:listitem>
<asp:listitem >business</asp:listitem>
<asp:listitem >popular_comp</asp:listitem>
</asp:dropdownlist>
<asp:button type=submit text="lookup" onclick="submitbtn_click" runat="server"/>
<p>
<asp:datagrid id="mylist" headerstyle-backcolor="#aaaadd" backcolor="#ccccff" runat="server"/>
</form>
</center>
</body>
</html>
这个例子的运行示例在
http://tutorial.superexpert.com/quickstart/aspplus/samples/webforms/intro/intro75.aspx
数据表格(data grid)控件 <asp:datagrid runat=server>
给我们提供了一种非常简单的方法用传统的ui截面去显示数据查询的结果.asp+ 的开发者现在还可以通过<asp:datalist runat=server>
来定制数据列表显示来定制信息
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sql" %>
<html>
<head>
<link rel="stylesheet"href="intro.css">
</head>
<script language="vb" runat=server>
sub submitbtn_click(sender as object, e as eventargs)
dim ds as dataset
dim myconnection as sqlconnection
dim mycommand as sqldatasetcommand
myconnection = new sqlconnection("server=localhost;uid=sa;pwd=;database=pubs")
mycommand = new sqldatasetcommand("select * from titles where type=" + category.selecteditem.value + "", myconnection)
ds = new dataset()
mycommand.filldataset(ds, "titles")
mylist.datasource = ds.tables("titles").defaultview
mylist.databind()
end sub
</script>
<body>
<center>
<form action="intro8.aspx" method="post" runat="server">
<asp:adrotator advertisementfile="ads.xml" bordercolor="black" borderwidth=1 runat="server"/>
<h3> name: <asp:textbox id="name" runat="server"/>
category: <asp:dropdownlist id="category" runat=server>
<asp:listitem >psychology</asp:listitem>
<asp:listitem >business</asp:listitem>
<asp:listitem >popular_comp</asp:listitem>
</asp:dropdownlist>
<asp:button type=submit text="lookup" onclick="submitbtn_click" runat="server"/>
<p>
<asp:datalist id="mylist" repeatcolumns="2" borderwidth="0" runat="server">
<template name="itemtemplate">
<table>
<tr>
<td>
<img src=<%# databinder.eval(container.dataitem, "title_id", "/quickstart/aspplus/images/title-{0}.gif") %>>
</td>
<td width=250 valign=top>
<b><%# databinder.eval(container.dataitem, "title") %></b>
<br><br>
price: <%# databinder.eval(container.dataitem, "price", "${0}") %>
</td>
</tr>
</table>
</template>
</asp:datalist>
</form>
</center>
</body>
</html>
这个程序的运行例子在
http://tutorial.superexpert.com/quickstart/aspplus/samples/webforms/intro/intro8.aspx
