#12004/8/9 22:11:09
<%@ Page Language="VB" %>
<%@ Import namespace="system.data" %>
<%@ Import namespace="system.data.oledb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<script language="vb" runat="server">
sub page_load(sender as object,e as eventargs)
dim conn as new oledbconnection
dim strConn as string
dim cmd as oledbcommand
dim datard as oledbdatareader
dim strSQL as string
strConn="provider=sqloledb;data source=SQL服务器名\实例名;user id=sa;Password=SQL登录密码;initial catalog=pubs;"
conn.connectionstring=strConn
conn.open
strSQL="select * from authors"
cmd=new oledbcommand(strSQL,conn)
datard=cmd.ExecuteReader
dtgrd.datasource=datard
dtgrd.databind
conn.close
if not ispostback then
conn.open
cmd.commandtext="select au_Fname,Au_ID from authors"
cmd.connection=conn
datard=cmd.ExecuteReader
ddlCity.datasource=datard
ddlcity.datatextfield="au_fname"
ddlcity.datavaluefield="au_id"
ddlcity.databind
end if
end sub
sub ddlcity_click(sender as object,e as eventargs)
lblID.text="作者:" & ddlcity.selecteditem.text & "的ID号是:" & ddlcity.selecteditem.value
end sub
sub btn1_click(sender as object,e as eventargs)
lblMsg.text="你选择的是" & ddlcity.selecteditem.text & "他的ID号是" & ddlcity.selecteditem.value
end sub
</script>
<body>
<form runat="server">
<asp:Dropdownlist id="ddlCity" runat="server" OnSelectedIndexChanged="ddlcity_click" autopostback="true" />
<asp:Button Text="提交信息" id="btn" onClick="btn1_click" runat="server" />
<asp:Label ID="lblID" runat="server" />
<br>
<asp:Label ID="lblMsg" runat="server" />
<asp:DataGrid id="dtGrd" runat="server" />
</form>
</body>
</html>
编辑历史:[此帖最近一次被 dreamexpress 编辑过(编辑时间:2004-08-09 22:45:08)]