C#调用免费天气预报WebService

  1 using System;
  2 using System.Collections;
  3 using System.Configuration;
  4 using System.Data;
  5 using System.Linq;
  6 using System.Web;
  7 using System.Web.Security;
  8 using System.Web.UI;
  9 using System.Web.UI.HtmlControls;
 10 using System.Web.UI.WebControls;
 11 using System.Web.UI.WebControls.WebParts;
 12 using System.Xml.Linq;
 13 using MyWeather.WS;
 14 
 15 namespace MyWeather
 16 {
 17     public partial class _Default : System.Web.UI.Page
 18         
 19     {
 20         //WeatherWS ws = new WeatherWS();
 21 
 22 
 23         protected void Page_Load(object sender, EventArgs e)
 24         {
 25             
 26 
 27 
 28             if (!IsPostBack)
 29             {
 30                 BindProvinceData();
 31                 BindCityData();
 32 
 33                 ShowWeatherData();
 34            
 35             }
 36             
 37   
 38         }
 39 
 40         protected void drpProvince_SelectedIndexChanged(object sender, EventArgs e)
 41         {
 42             BindCityData();
 43 
 44             ShowWeatherData();
 45             
 46         }
 47 
 48 
 49 
 50         protected void drpCity_SelectedIndexChanged(object sender, EventArgs e)
 51         {
 52             ShowWeatherData();
 53         }
 54 
 55         /// <summary>
 56         /// 显示选定城市的天气
 57         /// </summary>
 58         void ShowWeatherData()
 59         {
 60             WeatherWS ws = new WeatherWS();
 61             string[] weathers = ws.getWeather(drpCity.SelectedValue, "");
 62             foreach (string item in weathers)
 63             {
 64                 Response.Write(item + "<br>");
 65             }
 66  
 67         }
 68 
 69 
 70         /// <summary>
 71         /// 绑定省
 72         /// </summary>
 73         void BindProvinceData()
 74         {
 75             WeatherWS ws = new WeatherWS();
 76             DataSet dsProvince = ws.getRegionDataset();
 77             drpProvince.DataSource = dsProvince.Tables[0].DefaultView;
 78 
 79             drpProvince.DataTextField = dsProvince.Tables[0].Columns[1].ColumnName; //"RegionName";
 80             drpProvince.DataValueField = dsProvince.Tables[0].Columns[0].ColumnName;//"RegionID";
 81 
 82             drpProvince.DataBind();
 83 
 84         }
 85         /// <summary>
 86         /// 绑定市
 87         /// </summary>
 88         void BindCityData()
 89         {
 90             WeatherWS ws = new WeatherWS();
 91             DataSet dsCity = ws.getSupportCityDataset(drpProvince.SelectedValue);
 92             drpCity.DataSource = dsCity.Tables[0].DefaultView;
 93 
 94             drpCity.DataTextField = dsCity.Tables[0].Columns[1].ColumnName; //"CityName";
 95             drpCity.DataValueField = dsCity.Tables[0].Columns[0].ColumnName; //"CityID";
 96 
 97             drpCity.DataBind();
 98         }
 99 
100 
101     }
102 }

 

posted @ 2016-07-27 22:59  林中小轩  阅读(2073)  评论(0编辑  收藏  举报