【 tulaoshi.com - ASP 】
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