比如有个textbox1。。代码里面找不到textbox1

解决方案 »

  1.   


    //FindControl
    protected void repeter_ItemCommand(object source, RepeaterCommandEventArgs e)
            {
                e.Item.FindControl("testbox1");
            }
      

  2.   

    foreach( RepeaterItem item in this.Repeater1.Items )   
    {
    TextBox txt=item.FindControl("TextBox1") as TextBox;   
    if(txt!=null){}
    } protected void Repeater_ItemDataBound(object obj, RepeaterItemEventArgs e)
      {
      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
      {TextBox txt=e.item.FindControl("TextBox1") as TextBox;  
      DataRowView row = (DataRowView)e.Item.DataItem;
      }
    }
      

  3.   


    这里已经写得比较全了,如果你用的是c#
    里面就不能用as 
    要这样:TextBox tb=(TextBox)item.FintControl("TextBox1");
      

  4.   

    调用FindControl(control's ID)方法
      

  5.   

     int delId = 0;
            //先遍历取得选中项            
            for (int i = 0; i < this.repeater1.Items.Count; i++)
            {
                CheckBox cbx = (CheckBox)repeater1.Items[i].FindControl("cbx");
                Label lbl = (Label)repeater1.Items[i].FindControl("lbl");
                if (cbx != null)
                {
                    if (cbx.Checked)
                    {
                        delId = Int32.Parse(lbl.Text);
                        PxgzBLLS pxbll = new PxgzBLLS();
                        pxbll.deletesAll(delId);
                        bind();
                    }
                }
            }