码迷,mamicode.com
首页 > Web开发 > 详细

C#用天气预报的WebServices

时间:2014-07-19 16:31:32      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:style   http   java   color   os   width   

后台代码: 

C#代码  bubuko.com,布布扣
  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#代码  bubuko.com,布布扣
  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引用

bubuko.com,布布扣  

 

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

C#用天气预报的WebServices,布布扣,bubuko.com

C#用天气预报的WebServices

标签:style   http   java   color   os   width   

原文地址:http://www.cnblogs.com/gc2013/p/3853985.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!