解决方案 »
- function功能实现问题,高手帮忙!!谢谢!!
- 求打印阿!
- 在asp中怎么根据字段查找数据在label控件中显示?
- 请教一个ASP.NET+AJAX异常处理的问题!
- 页面清空问题
- 使用XML帮助上传文件,js + asp.net(50)
- 单值数据绑定到底怎么用哦?
- EXCEL中写入数据后,文件没有保存成功!
- datalist 中button控件text文本怎么显示多个字段 怎么实现
- 请问接口INTERFACE和类CLASS有什么关系?
- gridview checkbox如何初始化赋值和排序
- 服务器上导数据到excl,出现System.Runtime.InteropServices.COMException (0x80(0x800A03EC):未找到
using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyWeather
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
DataSet mds = WeatherClass.getSupportDataSet();
if (!Page.IsPostBack)
{
DataTable dt = mds.Tables[0];//支持的省洲
this.Province.DataSource = dt;
this.Province.DataValueField = "ID";//Value存储省洲代码
this.Province.DataTextField = "Zone";//显示省洲名称
this.Province.DataBind();
City.SelectedIndex = 1;
CityDataBind("1");//默认直辖市
GetWeatherByCode("54511");// 默认北京
}
}
catch (Exception)
{
Title.Text = "发现一个错误";
}
}
/// <summary>
/// 根据城市代码取得该城市的天气,并绑定到相关的显示控件
/// </summary>
/// <param name="cityCode">城市代码</param>
protected void GetWeatherByCode(string cityCode)
{
String[] wa = WeatherClass.GetCityWeather(cityCode.Trim());//天气的字符串数组
Label1.Text = wa[10];
Label2.Text = wa[6] + " " + wa[5] + " " + wa[7];
Label3.Text = wa[13] + " " + wa[12] + " " + wa[14];
Label4.Text = wa[18] + " " + wa[17] + " " + wa[19];
Label5.Text = wa[11].Replace("\n", "<br />");
Label6.Text = wa[22].Replace("\n", "<br />");
Label7.Text = DateTime.Parse(wa[4]).ToString("yyyy年MM月dd日 dddd HH:mm");
Label8.Text = wa[0] + " / " + wa[1];
Image1.ImageUrl = "~/images/weather/" + wa[8];
Image2.ImageUrl = "~/images/weather/" + wa[9];
Image3.ImageUrl = "~/images/weather/" + wa[15];
Image4.ImageUrl = "~/images/weather/" + wa[16];
Image5.ImageUrl = "~/images/weather/" + wa[20];
Image6.ImageUrl = "~/images/weather/" + wa[21];
CityPhoto.ImageUrl = "http://www.cma.gov.cn/tqyb/img/city/" + wa[3];
CityPhoto.AlternateText = City.SelectedItem.Text;
}
/// <summary>
/// 绑定城市的数据,根据省洲代码对显示进行筛选
/// </summary>
/// <param name="zoneID">省洲代码</param>
protected void CityDataBind(string zoneID)
{
DataView dv = new DataView(WeatherClass.getSupportDataSet().Tables[1]);
dv.RowFilter = "[ZoneID] = " + zoneID;//筛选的条件是ZoneID=省洲代码
City.DataSource = dv;
City.DataTextField = "Area";
City.DataValueField = "AreaCode";
City.DataBind();
City.Items.Insert(0, new ListItem("选择城市", "0"));
City.SelectedIndex = 0;
}
/// <summary>
/// 省洲选择变化的事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Province_SelectedIndexChanged(object sender, EventArgs e)
{
CityDataBind(Province.SelectedItem.Value.Trim());
}
/// <summary>
/// 城市选择变化的事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void City_SelectedIndexChanged(object sender, EventArgs e)
{
if (City.Items[0].Value == "0")
{
City.Items.RemoveAt(0);
}
GetWeatherByCode(City.SelectedItem.Value.Trim());
}
}
}哈哈
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MyWeather
{
public class WeatherClass
{
/// <summary>
/// 取得支持的城市,若高速缓存中不存在则直接调用服务读取
/// 获得本天气预报Web Services支持的洲、国内外省份和城市信息
/// 输入参数:无;返回:DataSet 。DataSet.Tables(0) 为支持的洲和国内省份数据,
/// DataSet.Tables(1) 为支持的国内外城市或地区数据。
/// DataSet.Tables(0).Rows(i).Item("ID") 主键对应 DataSet.Tables(1).Rows(i).Item("ZoneID") 外键。
/// Tables(0):ID = ID主键,Zone = 支持的洲、省份;
/// Tables(1):ID 主键,ZoneID = 对应Tables(0)ID的外键,Area = 城市或地区,AreaCode = 城市或地区代码。
/// </summary>
/// <returns>返回记录集</returns>
public static DataSet getSupportDataSet()
{
DataSet ds = (DataSet)HttpContext.Current.Cache["dataSetCache"];//从高速缓存中读取记录集
if (ds == null)//若无此缓存
{
cn.com.webxml.www.WeatherWebService Weather = new MyWeather.cn.com.webxml.www.WeatherWebService();
ds = Weather.getSupportDataSet();
HttpContext.Current.Cache.Insert("dataSetCache", ds, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);//设置缓存
}
return ds;
}
/// <summary>
/// 根据城市代码取得城市天气,有高速缓存
/// </summary>
/// <param name="cityCode">城市代码</param>
/// <returns>返回天气字符串数组</returns>
public static string[] GetCityWeather(string cityCode)
{
string cacheName = "Weather" + cityCode.Trim();
string[] WeatherArray=(string[])HttpContext.Current.Cache[cacheName];
if (WeatherArray == null)
{
cn.com.webxml.www.WeatherWebService weather = new MyWeather.cn.com.webxml.www.WeatherWebService();
WeatherArray = weather.getWeatherbyCityName(cityCode.Trim());
HttpContext.Current.Cache.Insert(cacheName, WeatherArray, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
}
return WeatherArray;
}
}
}啊啊
调用一下这个网站的Webservice
http://www.cnblogs.com/ServerMaintaining/archive/2010/11/08/1871473.html打开这个链接,是WindowsForm程序,但是asp.net的获取天气预报信息方式和他是一样的,就自己改改显示方式就行。
265天气根据IP自动获得当地的天气情况
<iframe src="http://weather.265.com/weather.htm" width="168" height="54" frameborder="no" border="0" marginwidth="0&quoat; marginheight="0" scrolling="no"></iframe>
<BR>QQ天气预报代码(一)
<iframe width="145" height="130" border="0" align="center" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="http://minisite.qq.com/Weather/news_new.html" allowTransparency="true"></iframe>
<BR>QQ天气预报代码(二)
代码 :<IFRAME ID='ifm2' WIDTH='189' HEIGHT='190' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' SRC='http://weather.qq.com/inc/ss211.htm'></IFRAME>
<BR>
新浪天气预报代码
<IFRAME ID='ifm2' WIDTH='260' HEIGHT='70' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' src="http://news.sina.com.cn/iframe/weather/420101.html"></IFRAME>
<iframe width="260" height="195" frameborder=0 border=0 scrolling=no src="http://weather.265.com/weather.htm"></iframe>
效果图:
好的啊:[email protected],谢谢了