在程序的最开始定义了一个全局变量 public ArrayList List = new ArrayList();

button_click
{
    for (int i = 0; i <= 10; i++)
        {
            ……
            List.Add(zdListBox.Items.Count);   //zdlistboc.item是变化的,断点是也有值22,43,81……
            ……
        }
}然后
button2_click
{
   for ( i = 0; i < zdListBox.Items.Count - 1; i++)
        {
            for (j = i+1; j < zdListBox.Items.Count; j++)
            {
                if (zdListBox.Items[i].Text != zdListBox.Items[j].Text || (zdListBox.Items[i].Text == "ID" && zdListBox.Items[j].Text == "ID")) continue;
                
                    else
                    {
                        if (zdListBox.Items[i].Text != "ID" && zdListBox.Items[j].Text != "ID" && zdListBox.Items[i].Text == zdListBox.Items[j].Text)
                        {
                            for (k = 0; i <List.Count-1; k++)//提示List.Count=0;是什么原因啊?
                            {
                                if (i <= (int)List[k]) { m = k; break; }
                                else if (i > (int)List[k] && i <= (int)List[k + 1]) 
                                          { m = k + 1; break; }
                            }
                            for (int p = 0; i < List.Count-1; p++)
                            {
                                if (j <= (int)List[p]) { n = p; break; }
                                else if (j > (int)List[p] && i <= (int)List[p + 1]) 
                                           { n = p + 1; break; }
                            }
                        }
             }
                
            }
                
        }}

解决方案 »

  1.   

    当你点击 button2_click 回发的时候之前 button_click  中 list 设置的值已经丢了(实际上,这个 aspx.cs 类完全重新实例化的,重新执行一便初始化 public ArrayList List = new ArrayList(); ,但没有执行 button_click)
      

  2.   

    public static ArrayList List  = new ArrayList(); 
      

  3.   

    winform还是webform啊,如果是webform的话,应该把list保存到viewstate中,点button2后list中才有值
      

  4.   

    你可以放在 session 中// 定义属性,内部使用 Session
    public ArrayList List
    {
    get { ArrayList list = Session["__!List"] as ArrayList; if(list == null) { list = new ArrayList(); Session["__!List"] = list; }  return list; }
    }
      

  5.   

    页面回发后重新New了 建议你用viewstate[""] .
      

  6.   

    http 是无状态的,在 asp.net 中两次 Request 之间 Page 两个不同的对象的,每次请求玩这个 page 对象就被销毁了
      

  7.   

    问题解决了,呵呵,真好,我以为只有page_load刷新呢,谢谢楼上的帮忙……
      

  8.   

    刷没了.把你的ArrayList用ViewState存一下
      

  9.   

    同一个页面内用ViewState就可以了.