发布网友 发布时间:2022-04-23 09:52
共2个回答
热心网友 时间:2022-04-25 07:39
在SQL中建立一个server表
city province
南京 江苏
苏州 江苏
扬州 江苏
杭州 浙江
温州 浙江
宁波 浙江
null null(留空)
然后在Visual Studio新建项目
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
请选择省份<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="province" DataValueField="province">
</asp:DropDownList>
请选择城市<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
DataTextField="city" DataValueField="city">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:master %>"
SelectCommand="SELECT DISTINCT province FROM province"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:master %>"
SelectCommand="SELECT [city] FROM [province] WHERE ([province] = @province)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="province" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:Button ID="Button1" runat="server" Text="提交" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList1"
ErrorMessage="您没有选择省份!"></asp:RequiredFieldValidator>
<br />
欢迎来自<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:Label ID="Label2" runat="server"></asp:Label>的朋友!</div>
</form>
</body>
</html>
热心网友 时间:2022-04-25 08:57
我用PHP