当然了,肯定不是自己写代码了,调用了一个WebService来实现的。
(效果图)
首先添加Web 引用:http://www.ayandy.com/
后台代码:
using
System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using com.ayandy.www;
public partial class Default3 : System.Web.UI.Page
... {
protected void Page_Load(object sender, EventArgs e)
...{
}
protected void Button1_Click(object sender, EventArgs e)
...{
com.ayandy.www.Service obj = new Service();
string[] a1 = new string[10];
try
...{
a1 = obj.getWeatherbyCityName(TextBox1.Text, com.ayandy.www.theDayFlagEnum.Today);
Label1.Text = a1[1].ToString();
Label2.Text = a1[2].ToString();
Label3.Text = a1[3].ToString();
Label4.Text = a1[4].ToString();
Label5.Text = a1[5].ToString();
Image1.ImageUrl = a1[6].ToString();
}
catch ...{ }
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using com.ayandy.www;
public partial class Default3 : System.Web.UI.Page
... {
protected void Page_Load(object sender, EventArgs e)
...{
}
protected void Button1_Click(object sender, EventArgs e)
...{
com.ayandy.www.Service obj = new Service();
string[] a1 = new string[10];
try
...{
a1 = obj.getWeatherbyCityName(TextBox1.Text, com.ayandy.www.theDayFlagEnum.Today);
Label1.Text = a1[1].ToString();
Label2.Text = a1[2].ToString();
Label3.Text = a1[3].ToString();
Label4.Text = a1[4].ToString();
Label5.Text = a1[5].ToString();
Image1.ImageUrl = a1[6].ToString();
}
catch ...{ }
}
}
前台代码:
<%
...
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3"
%>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head runat ="server" >
< title > 无标题页 </ title >
</ head >
< body bgcolor ="aqua" >
< form id ="form1" runat ="server" >
< div >
< asp:Button ID ="Button1" runat ="server" OnClick ="Button1_Click" Text ="Button" />
< asp:TextBox ID ="TextBox1" runat ="server" ></ asp:TextBox >
< br />
< asp:Label ID ="Label1" runat ="server" Text ="Label" ></ asp:Label >
< br />
< asp:Label ID ="Label2" runat ="server" Text ="Label" ></ asp:Label >
< br />
< asp:Label ID ="Label3" runat ="server" Text ="Label" ></ asp:Label >
< br />
< asp:Label ID ="Label5" runat ="server" Text ="Label" ></ asp:Label >< br />
< asp:Label ID ="Label4" runat ="server" Text ="Label" ></ asp:Label >< br />
< asp:Image ID ="Image1" runat ="server" Height ="33px" Width ="32px" /></ div >
</ form >
</ body >
</ html >
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head runat ="server" >
< title > 无标题页 </ title >
</ head >
< body bgcolor ="aqua" >
< form id ="form1" runat ="server" >
< div >
< asp:Button ID ="Button1" runat ="server" OnClick ="Button1_Click" Text ="Button" />
< asp:TextBox ID ="TextBox1" runat ="server" ></ asp:TextBox >
< br />
< asp:Label ID ="Label1" runat ="server" Text ="Label" ></ asp:Label >
< br />
< asp:Label ID ="Label2" runat ="server" Text ="Label" ></ asp:Label >
< br />
< asp:Label ID ="Label3" runat ="server" Text ="Label" ></ asp:Label >
< br />
< asp:Label ID ="Label5" runat ="server" Text ="Label" ></ asp:Label >< br />
< asp:Label ID ="Label4" runat ="server" Text ="Label" ></ asp:Label >< br />
< asp:Image ID ="Image1" runat ="server" Height ="33px" Width ="32px" /></ div >
</ form >
</ body >
</ html >