<%@ Page Language="VB" Debug="true"%>
<%@ import namespace="system.data.oledb"%>
<%@ import namespace="system.data"%>
<html><head>
<script runat="server">
Sub Page_init(Src As Object, E As EventArgs)
dim dbconn as oledbconnection '聲明一個資料庫連接對象
dim dbcommand as oledbdataadapter '利用oledbdataadapter對象聲明一個資料檢索
dim dspagedata as new dataset '利用dataset儲存檢索結果的資料
dbconn=new oledbconnection("provider=sqloledb;server=thc;initial catalog=thc;user id=sa;pwd=980123;") '資料庫連接
dbcommand = new oledbdataadapter("select id,quert,name from thcjp", dbconn) '從thcjp表中檢索資料
dbcommand.fill(dspagedata,"thcjp") '把紀錄放在dataset對象中一個名為“thcjp”的表中
dbcommand.fill(dspagedata,"thcjp1")
ddlthcjp.datasource=dspagedata.tables("thcjp").defaultview '定義所用dataset表的名字
ddlthcjp1.datasource=dspagedata.tables("thcjp1").defaultview
ddlthcjp.databind() '綁定這個表
ddlthcjp1.databind()
End Sub
sub btn_click(Src As Object, E As EventArgs)
lbl.text="先頭那個框框寫的是:" & ddlthcjp.selecteditem.text & "<br>第二個框框裡頭選的是: "& ddlthcjp1.selecteditem.text
end sub
</script>
</head><body>
<form runat="server">
<asp:DropDownList ID="ddlthcjp" runat="server" DataTextField="name" DataValueField="id"/>
<asp:DropDownList ID="ddlthcjp1" runat="server" DataTextField="quert" DataValueField="id"/>
<asp:Button ID="btn" runat="server" Text="提交" OnClick="btn_click" />
</form>
<asp:Label ID="lbl" runat="server"/>
</body></html>