예제 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         //获得本天气预报服务支持的洲、国内外省份和城市信息
         DataSet ds = weather.getSupportDataSet();
         if (!Page.IsPostBack)
         {
             DataTable dt = ds.Tables[0];
             ddlProvince.DataSource = dt;
             //将支持的洲、国内省份(直辖市、特别行政区)代码绑定到DataValueField
             ddlProvince.DataValueField = "ID";
             //将支持的洲、国内省份(直辖市、特别行政区)名称绑定到DataTextField
             ddlProvince.DataTextField = "Zone";//显示省洲名称
             ddlProvince.DataBind();
             ddlCity.SelectedIndex = 1;
             //调用自定义方法CityDataBind(),"1"表示直辖市
             CityDataBind("1");
             //调用自定义方法GetWeatherByCode(),"54511"表示北京
             GetWeatherByCode("54511");
         }
     }
     catch (Exception)
     {
         lblError.Text = "网络连接异常!";
     }
 }
예제 #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         DataSet ds = weather.getSupportDataSet();
         if (!IsPostBack)
         {
             DataTable dt = ds.Tables[0];
             DropDownList1.DataSource     = dt;
             DropDownList1.DataValueField = "ID";
             DropDownList1.DataTextField  = "Zone";
             DropDownList1.DataBind();
             DropDownList2.SelectedIndex = 1;
             CityDataBind("1");
             GetWeather("54511");
         }
     }
     catch (Exception)
     {
         Label6.Text = "网络连接异常";
     }
 }