首页上一页 1 下一页尾页 3 条记录 1/1页
ASP.NET程序开发范例宝典请教问题(一) 有关天气预报
发表在ASP.NET图书答疑
2010-07-14
是否精华
是
否
版块置顶:
是
否
昨天这段代码还能运行,今天运行时说红色部分“未将对象引用设置到对象的实例” 请问这是什么原因? 在线等待
public partial class _Default : System.Web.UI.Page
{
obj.Service myobj = new obj.Service(); //实例化
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindPro();
BindCity();
BindWeather();
}
}
// 获得省份
protected void BindPro()
{
string [] pro=myobj.getSupportProvince();
for (int i = 1; i <= Int32 .Parse (pro[0]); i++)
{
DropDownList1.Items.Add(new ListItem (pro[i].ToString (),pro[i].ToString()));
}
}
//获得城市
protected void BindCity()
{
DropDownList2.Items.Clear();
string[] city = myobj.getSupportCity (DropDownList1 .SelectedValue );
for (int i = 1; i <= Int32.Parse(city[0]); i++)
{
DropDownList2.Items.Add(new ListItem(city[i].ToString(), city[i].ToString()));
}
}
//天气预报
protected void BindWeather()
{
string[] mystr = myobj.getWeatherbyCityName(DropDownList2 .SelectedValue , theDayFlagEnum.Today);
Label1.Text = mystr[1].ToString();
Label2.Text = mystr[2].ToString();
Label3.Text = mystr[3].ToString();
[font color=#FF0000]Label4.Text = mystr[4].ToString();[/font]
Label5.Text = mystr[5].ToString();
Image1.ImageUrl = mystr[6].ToString();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
BindCity();
}
protected void Button1_Click(object sender, EventArgs e)
{
BindWeather();
}
}
public partial class _Default : System.Web.UI.Page
{
obj.Service myobj = new obj.Service(); //实例化
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindPro();
BindCity();
BindWeather();
}
}
// 获得省份
protected void BindPro()
{
string [] pro=myobj.getSupportProvince();
for (int i = 1; i <= Int32 .Parse (pro[0]); i++)
{
DropDownList1.Items.Add(new ListItem (pro[i].ToString (),pro[i].ToString()));
}
}
//获得城市
protected void BindCity()
{
DropDownList2.Items.Clear();
string[] city = myobj.getSupportCity (DropDownList1 .SelectedValue );
for (int i = 1; i <= Int32.Parse(city[0]); i++)
{
DropDownList2.Items.Add(new ListItem(city[i].ToString(), city[i].ToString()));
}
}
//天气预报
protected void BindWeather()
{
string[] mystr = myobj.getWeatherbyCityName(DropDownList2 .SelectedValue , theDayFlagEnum.Today);
Label1.Text = mystr[1].ToString();
Label2.Text = mystr[2].ToString();
Label3.Text = mystr[3].ToString();
[font color=#FF0000]Label4.Text = mystr[4].ToString();[/font]
Label5.Text = mystr[5].ToString();
Image1.ImageUrl = mystr[6].ToString();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
BindCity();
}
protected void Button1_Click(object sender, EventArgs e)
{
BindWeather();
}
}