protected void Button4_Click(object sender, EventArgs e)
    {
        List<int> ids = new List<int>();
        List<int> counts = new List<int>();
        foreach (RepeaterItem repeaitem in this.Repeater1.Items)
        {
            Label labID = repeaitem.FindControl("G_ID") as Label;
            TextBox txtcount = repeaitem.FindControl("txtcount") as TextBox;
            ids.Add(Convert.ToInt32(labID.Text.Trim()));
            counts.Add(Convert.ToInt32(txtcount.Text.Trim()));
        }
        for (int i = 0; i < ids.Count; i++)
        {
            string Gsql = string.Format("update Cart set G_AMOUNT={0} where G_ID={1} ", counts[i], ids[i]);
            //string sql = "update Cart set G_AMOUNT=" + counts[i] + "where G_ID="+ids[i]+"";
            Class1.ExecSql(Gsql);
        }        BindCarlist();
            
    }
为什么进不到foreach()里面去执行?

解决方案 »

  1.   

    你的Repeater1控件中有内容吗?是否绑定了数据源呢?
    看看this.Repeater1.Items.count是否为0.
    我以前也遇过,后来发现没绑定数据.
      

  2.   

     foreach (RepeaterItem repeaitem in Repeater1.Items) 
    试下
      

  3.   

    foreach (control repeaitem in Repeater1.Controls) 
    {}
      

  4.   

     foreach (RepeaterItem item in this.Repeater1.Items)
            {
                Response.Write((item.FindControl("Label1") as Label).Text.ToString());
            }
      

  5.   

      foreach (RepeaterItem item in Repeater1.Items)
        {
          chkExport = (CheckBox)item.FindControl("chkExport");
         }