Web Service获取天气预报

Web Service获取天气预报功能,步骤:

1、先建一个页面,用table布局,放置2DropDownList控件和一个Button控件,5label控件,一个Image控件。

2、在网站根目录右击,在弹出的对话框中选择添加Web引用,在URL地址中输入:http://www.ayandy.com/Service.asmx 单击前往,在“Web引用名中输入“App_WebReferences”,点击添加引用

3、代码实现:

 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

using System.Web.Services;   //添加引用

public partial class Index : System.Web.UI.Page
{
    App_WebReferences.Service myobj = new App_WebReferences.Service();   //
实例化

protected void Page_Load(object sender, EventArgs e)
    {

          if (!IsPostBack)      //绑定信息

            {

            BindPro();
            BindCity();
            BindWeather();
            Label5.Text = DateTime.Now.ToShortDateString();

             }
     }

   protected void BindPro()              //绑定省份
    {
        string[] pro = myobj.getSupportProvince();
        for (int i = 1; i <= Int32.Parse(pro[0]); i++)
        {
            DropDownList1.Items.Add(new ListItem(pro[i].ToString(), pro[i].ToString()));
        }
    }
    protected void BindCity()        //
绑定城市
    {
        DropDownList2.Items.Clear();
        string[] city = myobj.getSupportCity(DropDownList1.SelectedValue);
        for (int i = 1; i <= Int32.Parse(city[0]); i++)
        {
            DropDownList2.Items.Add(new ListItem(city[i].ToString(), city[i].ToString()));
        }
    }
    protected void BindWeather()   //
绑定天气
    {
        string[] mystr = myobj.getWeatherbyCityName(DropDownList2.SelectedValue, App_WebReferences.theDayFlagEnum.Today);
        Label1.Text = mystr[1].ToString();
        Label2.Text = mystr[2].ToString();
        Label3.Text = mystr[3].ToString();
        Label4.Text = mystr[5].ToString();
        Image1.ImageUrl = mystr[6].ToString();

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        BindPro();
        BindCity();
        BindWeather();
    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值