1在网页中添加
天气预报查询
WebTianQi.aspx前台
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
Xonselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<asp:Button ID="btnChaKan" runat="server" Xοnclick="btnChaKan_Click" Text="查看" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
WebTianQi.aspx-后台
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
cn.com.webxml.www.WeatherWebService weather = new
cn.com.webxml.www.WeatherWebService();
this.DropDownList1.DataSource=weather.getSupportProvince();
this.DropDownList1.DataBind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
cn.com.webxml.www.WeatherWebService weather = new cn.com.webxml.www.WeatherWebService();
BindCity(weather);
}
private void BindCity(cn.com.webxml.www.WeatherWebService weather)
{
this.DropDownList2.Items.Clear();
string[] strs = weather.getSupportCity(this.DropDownList1.SelectedValue);
foreach (string item in strs)
{
DropDownList2.Items.Add(new ListItem(item.Substring(0, item.IndexOf("("))));
}
}
protected void btnChaKan_