定义了一个全局变量为什么它的值在下面却是为空的??

梦想开始的地方 2013-08-23 09:40:48



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});
}
}


这是怎么回事?把上面的数组带到下面来确是为空的 没有数据
说明:这是ascx页面的代码?我要在aspx中得到遍历出来的内容
或者可以把这个数组带到aspx中进行判断赋值?
这要怎么做?
...全文
470 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
public static ArrayList arl = new ArrayList();加一个static就可以咯!!
  • 打赏
  • 举报
回复
把它放Session怎么做?没有一点思路了!!
devmiao 2013-08-23
  • 打赏
  • 举报
回复
public static ArrayList arl = new ArrayList(); 或者放在session里面
  • 打赏
  • 举报
回复
我测试过了 有添加进去啊!!但是在下面的方法却得不到值?
  • 打赏
  • 举报
回复
debug一下啦,这句可能没执行arl.Add(ht.ID); //把我需要的内容添加进去
  • 打赏
  • 举报
回复
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}); } }
  • 打赏
  • 举报
回复
你赋值是在fill方法里赋的、在Button执行之前如果没有调用fill肯定是null啊

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧