BtunAdd下代码
        DataSet ds = new DataSet();
        string  sql = "select * from Zb_ProjectDetail where DetailType=1 and baseid=" + BaseID + " order by detailseq";
        ds = sv.GetData(sql, "Zb_ProjectDetail");  
        int Rowcount=ds.Tables["Zb_ProjectDetail"].Rows.Count;//几行        DataSet ds1 = new DataSet();
        string sql1 = "select DepId,seqid from zb_xmdep where qd=0 and baseid=" + BaseID + "order by seqid";
        ds1 = sv.GetData(sql1, "zb_xmdep");
        int Colcount = ds1.Tables["zb_xmdep"].Rows.Count;//几列
        for (int i = 0; i < Rowcount; i++)
        {
            TableRow tRow = new TableRow();
            Table1.Rows.Add(tRow);            for (int j = 1; j <= Colcount + 1; j++)//Colcount+1,加个名称字段,好看而已
            {
                
                if (j ==1)//第一列加个名称,方便查看,好对着输入
                {
                    Label chq = new Label();
                    chq.ID = "lab" + ds.Tables["Zb_ProjectDetail"].Rows[i]["pdetailid"];
                    chq.Width = 400;
                    chq.Text = ds.Tables["Zb_ProjectDetail"].Rows[i]["DetailSeq"].ToString()+"  "+ds.Tables["Zb_ProjectDetail"].Rows[i]["DetailName"].ToString();
                    TableCell tCell = new TableCell();
                    tRow.Cells.Add(tCell);
                    tCell.Controls.Add(chq);
                }
                else                                    
                {//生成控件
                    if (GetRootIsNull(BaseID, ds.Tables["Zb_ProjectDetail"].Rows[i]["detailid"].ToString()) == "0")
                    {
                        TableCell tCell = new TableCell();
                        tRow.Cells.Add(tCell);
                        TextBox Tbx = new TextBox();                      
                        Tbx.Text = "0";
                        string Vname = "t"+ds1.Tables["zb_xmdep"].Rows[j - 2]["DepId"] + "_" + j.ToString() + ds.Tables["Zb_ProjectDetail"].Rows[i]["pdetailid"];
                        Tbx.ID = Vname;
                        Tbx.Width = 30;
                        tCell.Controls.Add(Tbx);                       
                        DetailCount = DetailCount + 1;
                        StrTbx.Add(Vname);//定义的字符数组
                       
                        
                    }
                }            }
        }
    }

解决方案 »

  1.   

    BtnSave下代码(当然,代码)  
         string DepID;
            string DetailID;
            string lsstr;
            int x;
            string xxxxx;//玩的,无用
            for (int i = 1; i < DetailCount; i++)
            {
                lsstr = StrTbx[i].ToString();
                Control myControl1 = FindControl(lsstr);
                if (myControl1 != null)
                {
                    xxxxx = ((TextBox)Table1.FindControl(lsstr)).Text;//找不到控件,报无法引用错误
                    x = lsstr.IndexOf("_");
                    DepID = lsstr.Substring(0, x);
                    DetailID = lsstr.Substring(x + 1, lsstr.Length - x - 1);
                }
                       
            }
           
        }
      

  2.   

    先取得Table控件 然后才可以取得里面的 TextBox
    不可以直接取到TextBox的值的
    Controls 是一级一级的 要逐级遍历的
      

  3.   

    支持楼上,先取得Table控件,然后才可以取得里面的TextBoxTable.Controls
      

  4.   

    帮着顶顶贴!---------
    个人签名:
    ------------------------------------
    孙悟空分类信息网-分类信息全掌握!
    www.sun5kong.cn
    www.sun5kng.com.cn
    ------------------------------------
    集成100多种搜索引擎,抛弃搜索烦恼
    http://www.allss.com.cn
    ------------------------------------
    免费空间虚拟主机ASP.NET2.0+SQL 2000
    http://www.myidc.info
    ------------------------------------
    http://www.myidc.info 
    QQ:43909413
    ------------------------------------
      

  5.   

    哪位老大能给点代码看看!
    现在问题是我下面的代码在BtnAdd按钮下能调用TextBox.Text值,但是换到BtnAdd按钮下就无法调用
    (string str = ((TextBox)Table1.FindControl(lsstr)).Text)
      

  6.   

    刚才写错了个字。
    哪位老大能给点代码看看!
    现在问题是我下面的代码在BtnAdd按钮下能调用TextBox.Text值,但是换到BtnSave按钮下就无法调用
    (string str = ((TextBox)Table1.FindControl(lsstr)).Text)
      

  7.   

    BtnSave下的代码..............................
            string DepID;
            string DetailID;
            string lsstr;
            int x;
            string StrValue;//获取的TextBox.Text
            for (int i = 1; i < DetailCount; i++)
            {
                lsstr = StrTbx[i].ToString();
                Control myControl1 = Table1.FindControl(lsstr);
                if (myControl1 != null)//在这里等于空(郁闷中,为什么是空呢)
                {
                    StrValue = ((TextBox)Table1.FindControl(lsstr)).Text;
                    x = lsstr.IndexOf("_");
                    DepID = lsstr.Substring(0, x);
                    DetailID = lsstr.Substring(x + 1, lsstr.Length - x - 1);
                    
                }
           
          
            }