Frequent query of weather forecasts using Web Services

Source: Internet
Author: User

Steps:

1. Create a page first and use table layout to prevent two dropdownlist controls, one button control, five label controls, and one image control.
2. Right-click the website root directory, select Add web reference in the pop-up dialog box, enter: http://www.ayandy.com/Service.asmx in URL address, click go ", in "Web reference name", enter "app_webreferences" and click "add reference ".
3. Code implementation:

Show Code
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; // Add reference

Public partial class index: system. Web. UI. Page
{
App_webreferences.service myobj = new app_webreferences.service (); // instantiate

Protected void page_load (Object sender, eventargs E)
{

If (! Ispostback) // binding information

{

Bindpro ();
Bindcity ();
Bindweather ();
Label5.text = datetime. Now. tow.datestring ();

}
}

Protected void bindpro () // bind the province
{
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 () // bind City
{
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 () // bind the weather
{
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 button#click (Object sender, eventargs E)
{
Bindpro ();
Bindcity ();
Bindweather ();
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.