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 ();
}
}