aspnet企业级开发:显示天气预报
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 using System.Data; 8 9 public partial class _3_6 : System.Web.UI.Page 10 { 11 protected void Page_Load(object sender, EventArgs e) 12 { 13 if(!IsPostBack){ 14 GridView1.DataSource = null; 15 GridView1.DataBind(); 16 } 17 //开始时没有数据,但也要空绑定,来显示EmptyDataText的内容,不然不能显示 18 } 19 protected void Button1_Click(object sender, EventArgs e) 20 { 21 cn.com.webxml.www.WeatherWebService ser = new cn.com.webxml.www.WeatherWebService(); 22 /*右键项目,选择"添加web引用....",然后粘贴url: 23 http://www.webxml.com.cn/WebServices/WeatherWebService.asmx 24 添加天气预报web服务,这样便可引用上述代码 25 */ 26 string[] temp=ser.getWeatherbyCityName(TextBox1.Text); 27 //字符串数组被视作一列来绑定 28 GridView1.DataSource = temp; 29 GridView1.DataBind(); 30 } 31 }