后台代码: 

C#代码  收藏代码
  1. protected void Page_Load(object sender, EventArgs e)  
  2.    {  
  3.        if (!IsPostBack)  
  4.        {  
  5.            WeatherWS ws = new WeatherWS();  
  6.            IList<string> provinceDataSource = new List<string>();  
  7.   
  8.            DataSet proDs = ws.getRegionDataset();  
  9.            ddlProvince.DataSource = proDs.Tables[0].DefaultView;  
  10.            ddlProvince.DataTextField = "RegionName";  
  11.            ddlProvince.DataValueField = "RegionID";  
  12.            ddlProvince.DataBind();  
  13.        }  
  14.    }  
  15.   
  16.    protected void Button1_Click(object sender, EventArgs e)  
  17.    {  
  18.   
  19.        WeatherWS ws = new WeatherWS();  
  20.        string [] wsInfo = ws.getWeather(ddlCity.SelectedValue,"");  
  21.        string result = string.Empty;  
  22.        for (int i = 0; i < wsInfo.Length; i++)  
  23.        {  
  24.            result += wsInfo[i]+"<BR/>";  
  25.        }  
  26.        Label1.Text = result;  
  27.   
  28.    }  
  29.   
  30.    protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)  
  31.    {  
  32.        WeatherWS ws = new WeatherWS();  
  33.        DataSet cityDs = ws.getSupportCityDataset(ddlProvince.SelectedValue);  
  34.        ddlCity.DataSource = cityDs.Tables[0].DefaultView;  
  35.        ddlCity.DataTextField = "CityName";  
  36.        ddlCity.DataValueField = "CityID";  
  37.        ddlCity.DataBind();  
  38.    }  

 .aspx代码 

C#代码  收藏代码
  1. <asp:UpdatePanel ID="UpdatePanel1" runat="server">  
  2.                 <ContentTemplate>  
  3.                     <asp:DropDownList ID="ddlProvince" runat="server" AutoPostBack="True"   
  4.                         onselectedindexchanged="ddlProvince_SelectedIndexChanged">  
  5.                     </asp:DropDownList>  
  6.                     <asp:DropDownList ID="ddlCity" runat="server">  
  7.                     </asp:DropDownList>  
  8.                     <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />  
  9.                     <br />  
  10.                     <br />  
  11.                     <br />  
  12.                     <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>  
  13.                 </ContentTemplate>  
  14.             </asp:UpdatePanel>  

 访问速度很慢,,,... 

第一步要添加Web引用

 

 

然后页面就有东西了.....webServices给的很明确了

posted on 2014-07-18 17:26  GC2013  阅读(546)  评论(0编辑  收藏  举报