linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘网络学院网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > 开发语言 > asp.net >
栏目导栏
  php
  JSP
  ASP
  asp.net
  JAVA
  c/c++/c#
  perl
  JavaScript
  Basic
  Delphi
资料搜索
热门文章
·NetBPM工作流的一个示例:请假
·Office Web Components(OWC)绘
·asp.net正则表达式语法
·asp.net 2.0 ajax中使用PopupC
·Ado.Net读取Excel常见问题总结
·数据源为空时如何让GridView显
·如何让UpdatePanel支持文件上传
·C#.Net的常见面试试题和参考答
·asp.net ajax客户端编程+jquer
·Brettle.Web.NeatUpload.dll支
·ASP.NET使用Cookie
·ASP.NET DEMO 15: 同时支持行单
·如何使IE的后退按钮无效
·如何在ASP.NET中用OWC绘制图表
·asp.net:正确判断当前用户角色
最新文章
·Ajax Control Toolkit Animati
·讨论一下类似BlogEngine内一次
·使用CSS+SiteMap+UserControl+
·Asp.net中多彩下拉框的实现
·浅谈ASP.NET的Postback
·分清ASP.NET AJAX中的Extender
·Tip:在使用AjaxControlTookit
·有关注册DataItem的一些可能被
·IIRF(Ionic's Isapi Rewrite
·asp.net 客户端回调功能的实现
·关于控件部分的看法--读Progra
·为什么在vista上做开发
·如何封装JS和CSS文件为服务器端
·岂今我看过的最强的排序算法
·设计模式学习笔记之单件模式
Google
 
ASP.NET的实时天气及24小时天气预报(C#)
[ 作者:  加入时间:2007-10-16 14:12:07  来自:Linux联盟收集整理 ]
 ASP.NET的实时天气及24小时天气预报(C#) SDhLinux联盟
  修改其中的url获得其他城市的天气情况 SDhLinux联盟
  如广州为: SDhLinux联盟
  http://weather.yahoo.com/forecast/CHXX0037_c.html SDhLinux联盟
  注意仅适用于获得yahoo上的天气预报 SDhLinux联盟
   SDhLinux联盟
   SDhLinux联盟
  GetWeather.aspx SDhLinux联盟
  ----------------------------------- SDhLinux联盟
   SDhLinux联盟
  <%@ Page language="c#" Codebehind="GetWeather.aspx.cs" AutoEventWireup="false" Inherits="test.GetWeather" %> SDhLinux联盟
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > SDhLinux联盟
  <HTML> SDhLinux联盟
   <HEAD> SDhLinux联盟
   <title>GetWeather</title> SDhLinux联盟
   <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> SDhLinux联盟
   <meta name="CODE_LANGUAGE" Content="C#"> SDhLinux联盟
   <meta name="vs_defaultClientScript" content="JavaScript"> SDhLinux联盟
   <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> SDhLinux联盟
   </HEAD> SDhLinux联盟
   <body> SDhLinux联盟
   <form id="GetWeather" method="post" runat="server"> SDhLinux联盟
   <FONT face="宋体"> SDhLinux联盟
   <P> SDhLinux联盟
   <asp:Label id="lblWeather" runat="server">Weather</asp:Label></P> SDhLinux联盟
   <P> SDhLinux联盟
   <asp:Button id="btnGet" runat="server" Text="Get Weather"></asp:Button></P> SDhLinux联盟
   <P> SDhLinux联盟
   <asp:Label id="Weather2" runat="server">24小时天气</asp:Label></P> SDhLinux联盟
   <P> SDhLinux联盟
   <asp:Button id="btnGet2" runat="server" Text="天气预报"></asp:Button></P> SDhLinux联盟
   </FONT> SDhLinux联盟
   </form> SDhLinux联盟
   </body> SDhLinux联盟
  </HTML> SDhLinux联盟
   SDhLinux联盟
   SDhLinux联盟
   SDhLinux联盟
   SDhLinux联盟
   SDhLinux联盟
  getWeather.aspx.cs SDhLinux联盟
  --------------------------------------- SDhLinux联盟
   SDhLinux联盟
  using System; SDhLinux联盟
  using System.Collections; SDhLinux联盟
  using System.ComponentModel; SDhLinux联盟
  using System.Data; SDhLinux联盟
  using System.Drawing; SDhLinux联盟
  using System.Web; SDhLinux联盟
  using System.Web.SessionState; SDhLinux联盟
  using System.Web.UI; SDhLinux联盟
  using System.Web.UI.WebControls; SDhLinux联盟
  using System.Web.UI.HtmlControls; SDhLinux联盟
  using System.Net; SDhLinux联盟
  using System.IO; SDhLinux联盟
   SDhLinux联盟
  namespace test SDhLinux联盟
  { SDhLinux联盟
   SDhLinux联盟
   public class GetWeather : System.Web.UI.Page SDhLinux联盟
   { SDhLinux联盟
   protected System.Web.UI.WebControls.Label lblWeather; SDhLinux联盟
   protected System.Web.UI.WebControls.Label Weather2; SDhLinux联盟
   protected System.Web.UI.WebControls.Button btnGet2; SDhLinux联盟
   protected System.Web.UI.WebControls.Button btnGet; SDhLinux联盟
   SDhLinux联盟
   private void Page_Load(object sender, System.EventArgs e) SDhLinux联盟
   { SDhLinux联盟
   // Put user code to initialize the page here SDhLinux联盟
   } SDhLinux联盟
   SDhLinux联盟
   #region Web Form Designer generated code SDhLinux联盟
   override protected void OnInit(EventArgs e) SDhLinux联盟
   { SDhLinux联盟
   // SDhLinux联盟
   // CODEGEN: This call is required by the ASP.NET Web Form Designer. SDhLinux联盟
   // SDhLinux联盟
   InitializeComponent(); SDhLinux联盟
   base.OnInit(e); SDhLinux联盟
   } SDhLinux联盟
   SDhLinux联盟
   /// <summary> SDhLinux联盟
   /// Required method for Designer support - do not modify SDhLinux联盟
   /// the contents of this method with the code editor. SDhLinux联盟
   /// </summary> SDhLinux联盟
   private void InitializeComponent() SDhLinux联盟
   { SDhLinux联盟
   this.btnGet.Click += new System.EventHandler(this.btnGet_Click); SDhLinux联盟
   this.btnGet2.Click += new System.EventHandler(this.btnGet2_Click); SDhLinux联盟
   this.Load += new System.EventHandler(this.Page_Load); SDhLinux联盟
   SDhLinux联盟
   } SDhLinux联盟
   #endregion SDhLinux联盟
   SDhLinux联盟
   private void btnGet_Click(object sender, System.EventArgs e) SDhLinux联盟
   { SDhLinux联盟
   SDhLinux联盟
   WebRequest wreq=WebRequest.Create("http://weather.yahoo.com/forecast/CHXX0037_c.html"); SDhLinux联盟
   SDhLinux联盟
   HttpWebResponse wresp=(HttpWebResponse)wreq.GetResponse(); SDhLinux联盟
   SDhLinux联盟
   string HTML =""; SDhLinux联盟
   Stream s=wresp.GetResponseStream(); SDhLinux联盟
   SDhLinux联盟
   StreamReader objReader = new StreamReader(s); SDhLinux联盟
   SDhLinux联盟
   string sLine = ""; SDhLinux联盟
   int i = 0; SDhLinux联盟
   SDhLinux联盟
   while (sLine!=null) SDhLinux联盟
   { SDhLinux联盟
   i++; SDhLinux联盟
   sLine = objReader.ReadLine(); SDhLinux联盟
   if (sLine!=null) SDhLinux联盟
   HTML += sLine; SDhLinux联盟
   } SDhLinux联盟
   SDhLinux联盟
   String temp= ""; SDhLinux联盟
   int start,stop; SDhLinux联盟
   SDhLinux联盟
   start = HTML.IndexOf("<!-- CURCON-->",0,HTML.Length); SDhLinux联盟
   SDhLinux联盟
   stop = HTML.IndexOf("<!-- END CURCON-->",0,HTML.Length); SDhLinux联盟
   SDhLinux联盟
   temp = HTML.Substring(start, stop - start); SDhLinux联盟
   start = temp.IndexOf("<b>"); SDhLinux联盟
   stop = temp.IndexOf("</b>"); SDhLinux联盟
   SDhLinux联盟
   string degree = temp.Substring(start+3,stop - start -3); SDhLinux联盟
   SDhLinux联盟
   start = temp.IndexOf("<img"); SDhLinux联盟
   stop = temp.IndexOf("</td>",start); SDhLinux联盟
   SDhLinux联盟
   string img = temp.Substring(start,stop - start); SDhLinux联盟
   lblWeather.Text = degree + "<br>" + img; SDhLinux联盟
   SDhLinux联盟
   } SDhLinux联盟
   SDhLinux联盟
   private void btnGet2_Click(object sender, System.EventArgs e) SDhLinux联盟
   { SDhLinux联盟
   WebRequest wreq=WebRequest.Create("http://cn.weather.yahoo.com/CHXX/CHXX0037/index_c.html"); SDhLinux联盟
   SDhLinux联盟
   HttpWebResponse wresp=(HttpWebResponse)wreq.GetResponse(); SDhLinux联盟
   SDhLinux联盟
   string HTML =""; SDhLinux联盟
   Stream s=wresp.GetResponseStream(); SDhLinux联盟
   SDhLinux联盟
   StreamReader objReader = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312")); SDhLinux联盟
   SDhLinux联盟
   SDhLinux联盟
   string sLine = ""; SDhLinux联盟
   int i = 0; SDhLinux联盟
   SDhLinux联盟
   while (sLine!=null) SDhLinux联盟
   { SDhLinux联盟
   i++; SDhLinux联盟
   sLine = objReader.ReadLine(); SDhLinux联盟
   if (sLine!=null) SDhLinux联盟
   HTML += sLine; SDhLinux联盟
   } SDhLinux联盟
   SDhLinux联盟
   String temp= ""; SDhLinux联盟
   int start,stop; SDhLinux联盟
   SDhLinux联盟
   start = HTML.IndexOf("<table border=0 cellpadding=2 cellspacing=1 bgcolor=9999cc width=\"85%\">",0,HTML.Length); SDhLinux联盟
   SDhLinux联盟
   stop = HTML.IndexOf("</table>",start)+8; SDhLinux联盟
   SDhLinux联盟
   SDhLinux联盟
   temp = HTML.Substring(start, stop - start); SDhLinux联盟
   Weather2.Text = temp; SDhLinux联盟
   } SDhLinux联盟
   } SDhLinux联盟
  } SDhLinux联盟
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
无相关信息