MonitorDropDownList_SelectedIndexChanged函数不能实现与全局变量之间的传值
protected void MonitorDropDownList_SelectedIndexChanged(object sender, EventArgs e){
this.Label1.Text = this.MonitorDropDownList.SelectedValue;
}
protected void search_Click(object sender, EventArgs e)
{
GetMoniterPlaceData();
}
public void GetMoniterPlaceData()
{
//获取监测点编号
int moniterplaceid = Convert.ToInt32(Label1.Text.ToString());
//把对象函数添加到IList<>函数中
IList<FWSync.Model.MoniterPlaceInfo> MP = new List<FWSync.Model.MoniterPlaceInfo>();
MoniterPlace moniterplace = new MoniterPlace();
MP.Add(moniterplace.GetMoniterPlaceByMoniterPlaceID(moniterplaceid));
for (int i = 0; i < MP.Count; i++)
{
MoniterPlaceNameLabel.Text = MP[i].MoniterPlaceName;
}
}
这样通过this.Label1.Text 是能实现protected void MonitorDropDownList_SelectedIndexChanged(object sender, EventArgs e)这个函数传值的,
但是换成全局变量就这个函数就不执行了,就不能实现了,为什么????换成全局代码的如下:
int Mpid;//全局变量
protected void MonitorDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
Mpid = Convert.ToInt32(this.MonitorDropDownList.SelectedValue);
}
protected void search_Click(object sender, EventArgs e)
{
GetMoniterPlaceData();
}
public void GetMoniterPlaceData()
{
//获取监测点编号
int moniterplaceid = Mpid;
//把对象函数添加到IList<>函数中
IList<FWSync.Model.MoniterPlaceInfo> MP = new List<FWSync.Model.MoniterPlaceInfo>();
MoniterPlace moniterplace = new MoniterPlace();
MP.Add(moniterplace.GetMoniterPlaceByMoniterPlaceID(moniterplaceid));
for (int i = 0; i < MP.Count; i++)
{
MoniterPlaceNameLabel.Text = MP[i].MoniterPlaceName;
}
}
这样通过this.Label1.Text 是能实现protected void MonitorDropDownList_SelectedIndexChanged(object sender, EventArgs e)这个函数传值的,
但是换成全局变量就这个函数就不执行了,就不能实现了,为什么????请各位高手指点一下,在此先谢谢各位了!!! label 全局变量 对象
补充:.NET技术 , ASP.NET