WAP之家:为您提供最全最新的WAP技术,CP.SP.3G等行业资讯。 WAP之家交流论坛全新开放 点击进入>>
WAP资讯 | 3G动态 | SP动态 | 运营商动态 | 内容商动态 | 制造商动态 | 论坛讨论>> 每次自动访问
WAP技术 | WAP源码 | 手机编程 | 手机源码 | 无线技术 | J2ME技术 | 手机软件 添加到收藏夹
IVR技术 | SP资料 | SMS MMS技术 | 商业方案 | IVR下载 | 书籍教程 | 工具软件 语言:繁體中文

WAP之家技术文章WAP教程网站教程用C#读取sina天气预报到wap页面

用C#读取sina天气预报到wap页面
作者:未知  来源:CSDN  发布时间:2006-8-8 16:14:51
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %><%@ Page language="c#" Codebehind="weather.aspx.cs" Inherits="goodwap.life.weather" AutoEventWireup="false" %><mobile:form id="Form1" runat="server">
<FONT face="宋体">
<mobile:Label id="Label3" runat="server" Font-Bold="True">【生活资讯】</mobile:Label>
<mobile:Label id="Label1" runat="server" Font-Italic="True">==天气预报==</mobile:Label>
<mobile:Label id="l_date" runat="server"></mobile:Label>
<mobile:Label id="l_city" runat="server"></mobile:Label>
<mobile:Label id="l_wea" runat="server"></mobile:Label>
<mobile:Label id="l_sky" runat="server"></mobile:Label>
<mobile:Label id="l_w1" runat="server"></mobile:Label>
<mobile:Label id="l_w2" runat="server"></mobile:Label>
<mobile:Label id="l_w3" runat="server"></mobile:Label>
<mobile:Label id="Label2" runat="server">【请选择城市名】:</mobile:Label>
<mobile:SelectionList id="s_weather" runat="server">
<Item Value="深圳" Text="深圳" Selected="True"></Item>
<Item Value="广州" Text="广州"></Item>
<Item Value="上海" Text="上海"></Item>
<Item Value="北京" Text="北京"></Item>
<Item Value="天津" Text="天津"></Item>
<Item Value="武汉" Text="武汉"></Item>
<Item Value="重庆" Text="重庆"></Item>
<Item Value="成都" Text="成都"></Item>
<Item Value="南京" Text="南京"></Item>
<Item Value="香港" Text="香港"></Item>
<Item Value="澳门" Text="澳门"></Item>
</mobile:SelectionList>
<mobile:Command id="Command1" runat="server">查 询</mobile:Command>
<mobile:Link id="Link1" runat="server" NavigateUrl="../default.aspx#Goodview">首 页</mobile:Link></FONT></mobile:form>

public class weather : System.Web.UI.MobileControls.MobilePage
...{
protected System.Web.UI.MobileControls.Label Label1;
protected System.Web.UI.MobileControls.Label Label2;
protected System.Web.UI.MobileControls.SelectionList s_weather;
protected System.Web.UI.MobileControls.Label l_date;
protected System.Web.UI.MobileControls.Label l_city;
protected System.Web.UI.MobileControls.Label l_wea;
protected System.Web.UI.MobileControls.Label l_sky;
protected System.Web.UI.MobileControls.Label l_w1;
protected System.Web.UI.MobileControls.Label l_w2;
protected System.Web.UI.MobileControls.Label l_w3;
protected System.Web.UI.MobileControls.Link Link1;
protected System.Web.UI.MobileControls.Command Command1;
protected System.Web.UI.MobileControls.Label Label3;
protected System.Web.UI.MobileControls.Form Form1;

private void Page_Load(object sender, System.EventArgs e)
...{
// 在此处放置用户代码以初始化页面
if (!Page.IsPostBack)
...{
string city = "深圳";
int start,stop;
string weather1,weather2,wea;
string wea_city = weather_city(city);
wea_city = wea_city.Replace(" ","");

start = wea_city.IndexOf("<b>",0,wea_city.Length);
stop = wea_city.IndexOf("</b>", start);
weather1 = wea_city.Substring(start, stop-start).Trim() + " ";
weather1 = weather1.Substring(3,8).Trim();

start = wea_city.IndexOf("<tdstyle="font-size:40px;font-family:TimesNewRoman;font-weight:bold;">",0,wea_city.Length);
stop = wea_city.IndexOf("℃",start) + 40;
weather2 = wea_city.Substring(start, stop-start);
weather2 = weather2.Substring(stop-start-42,40).Trim();
weather2 = weather2.Replace(" ","");

start = wea_city.IndexOf("<fontcolor=#183888><b>", 0, wea_city.Length);
stop = wea_city.IndexOf("</b></font>",start);
wea = wea_city.Substring(start,stop-start);
wea = wea.Substring(22,wea.Length-22) + "kbrk";
wea = wea.Replace(" ", "");
wea = wea.Replace(">", "k");
wea = wea.Replace("<", "k");
wea = wea.Replace("kbrk", "k");
string [] wall = null;
char[] seperator = ...{'k'};
wall = wea.Split(seperator);

/**///////////////////////////////////////
l_city.Text = "[城市]:" + city;
l_wea.Text = "[天气]:" + weather1;
l_sky.Text = "[温度]:" + weather2;
/**////////
l_date.Text = wall[0];
l_w1.Text = wall[1];
l_w2.Text = wall[2];
l_w3.Text = wall[3];
}
}

Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
...{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{ 
this.Command1.Click += new System.EventHandler(this.Command1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Command1_Click(object sender, System.EventArgs e)
...{
string city = s_weather.Selection.Value.Trim();
int start,stop;
string weather1,weather2,wea;
string wea_city = weather_city(city);
wea_city = wea_city.Replace(" ","");

start = wea_city.IndexOf("<b>",0,wea_city.Length);
stop = wea_city.IndexOf("</b>", start);
weather1 = wea_city.Substring(start, stop-start).Trim() + " ";
weather1 = weather1.Substring(3,8).Trim();

start = wea_city.IndexOf("<tdstyle="font-size:40px;font-family:TimesNewRoman;font-weight:bold;">",0,wea_city.Length);
stop = wea_city.IndexOf("℃",start) + 40;
weather2 = wea_city.Substring(start, stop-start);
weather2 = weather2.Substring(stop-start-42,40).Trim();
weather2 = weather2.Replace(" ","");

start = wea_city.IndexOf("<fontcolor=#183888><b>", 0, wea_city.Length);
stop = wea_city.IndexOf("</b></font>",start);
wea = wea_city.Substring(start,stop-start);
wea = wea.Substrin

[1] [2]  下一页

[] [返回上一页] [打 印]
文章评论

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码