ASP.Net天气预报

版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!


恰饭广告




实现效果:

天气预告

注意:

1. 数据来源于中国气象局,webService引用服务(http://www.webxml.com.cn/WebServices/WeatherWebService.asmx

2. 添加服务引用不再赘述,天气图标下载(http://www.webxml.com.cn/images/weather.zip

3. 免费用户24小时内有查询限制

WebForm1.aspx.cs主要代码:

public partial class WebForm1 : System.Web.UI.Page
    {
        WeatherService.WeatherWebService weather = new WeatherService.WeatherWebService();
        string[] res = new string[23];
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            string cityname = TextBox1.Text.Trim();
            res = weather.getWeatherbyCityName(cityname);
            if (TextBox1.Text=="")
            {
                labAir.Text = "请输入城市名称";
                return;
            }
            if (res[1] == "")
            {
                labAir.Text = "城市名称不存在";
                return;
            }
            else
            {
                txtAir.Text = res[10];
                txtLife.Text = res[11];
                labAir.Text = res[5];
                labSummary.Text = res[6];
                Image1.ImageUrl = @"images\weather\a_" + res[8];
                Image2.ImageUrl = @"images\weather\a_" + res[9];
            }
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            res = weather.getWeatherbyCityName(TextBox1.Text);
            if (DropDownList1.SelectedItem.Text=="今天")
            {
                labAir.Text = res[5];
                labSummary.Text = res[6];
                Image1.ImageUrl = @"images\weather\a_" + res[8];
                Image2.ImageUrl = @"images\weather\a_" + res[9];
            }
            if (DropDownList1.SelectedItem.Text == "明天")
            {
                labAir.Text = res[12];
                labSummary.Text = res[13];
                Image1.ImageUrl = @"images\weather\a_" + res[15];
                Image2.ImageUrl = @"images\weather\a_" + res[16];
            }
            if (DropDownList1.SelectedItem.Text == "后天")
            {
                labAir.Text = res[17];
                labSummary.Text = res[18];
                Image1.ImageUrl = @"images\weather\a_" + res[20];
                Image2.ImageUrl = @"images\weather\a_" + res[21];
            }
        }
    }

原文链接:https://www.idaobin.com/archives/1250.html

让我恰个饭吧.ヘ( ̄ω ̄ヘ)

支付宝 ——————- 微信
图片加载中图片加载中



恰饭广告

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

70 ÷ = 10