定义了一个全局变量为什么它的值在下面却是为空的??
[align=left]
public ArrayList arl = new ArrayList(); //我在这里定义了一个全局数组
public void Fill(ArrayList sdf)
{
ArrayList ar = sdf;
Model.stock stockInfo = null;
for (int i = 0; i < ar.Count; i++)
{
stockInfo = Bll.Stock.GetStockByUUID(ar[i].ToString());
HtmlTextArea ht = new HtmlTextArea();
ht.ID =stockInfo.uuid;
arl.Add(ht.ID); //把我需要的内容添加进去
ht.InnerText = stockInfo.remark;
Panel1.Controls.Add(ht);
}
}
public void Button()
{
Model.stock stockInfo = null;
for (int i = 0; i < arl.Count; i++) //在这里我去得不到他的值?显示的是为空
{
stockInfo = Bll.Stock.GetStockByUUID(arl[i].ToString());
string uuuid = stockInfo.uuid;
string vremark = stockInfo.remark;
this.Page.GetType().InvokeMember("ReadUCMessage", BindingFlags.InvokeMethod, null, this.Page, new object[] { uuuid, vremark});
}
}[/align]
这是怎么回事?把上面的数组带到下面来确是为空的 没有数据
说明:这是ascx页面的代码?我要在aspx中得到遍历出来的内容
或者可以把这个数组带到aspx中进行判断赋值?
这要怎么做? 全局变量 --------------------编程问答-------------------- 你赋值是在fill方法里赋的、在Button执行之前如果没有调用fill肯定是null啊 --------------------编程问答-------------------- [align=left] public void Button()
{
this.Fill(sdf); //这个sdf报错 这个sdf哪里来?
Model.stock stockInfo = null;
for (int i = 0; i < arl.Count; i++)
{
stockInfo = Bll.Stock.GetStockByUUID(arl[i].ToString());
string uuuid = stockInfo.uuid;
string vremark = stockInfo.remark;
Response.Write("<script>alert('编号为" + uuuid + "内容为" + vremark + "')</script>");
this.Page.GetType().InvokeMember("ReadUCMessage", BindingFlags.InvokeMethod, null, this.Page, new object[] { uuuid, vremark});
}
}[/align] --------------------编程问答-------------------- debug一下啦,这句可能没执行arl.Add(ht.ID); //把我需要的内容添加进去
--------------------编程问答-------------------- 我测试过了 有添加进去啊!!但是在下面的方法却得不到值? --------------------编程问答-------------------- public static ArrayList arl = new ArrayList();
或者放在session里面 --------------------编程问答-------------------- 把它放Session怎么做?没有一点思路了!! --------------------编程问答-------------------- --------------------编程问答-------------------- public static ArrayList arl = new ArrayList();加一个static就可以咯!!
补充:.NET技术 , C#