我用动态添加Table里面的行列同时也向里面加载了TextBox文本框!
for (int i = 2; i < 10; i++)
  {
     TableRow tempRow = new TableRow();
     TableCell tempCell1 = new TableCell();
     tempRow.Cells.Add(tempCell1);
     tempCell1.Text="awsdf"; for (int j = 1; j < 4; j++)
   {
      TableCell tempCell = new TableCell();
      TextBox   myddl   =   new TextBox();  
              myddl.ID="T"+Convert.ToString(i)+"M"+Convert.ToString(j);
               tempCell.Controls.Add( myddl);
               myddl.Text="sdfwsdf";
       tempRow.Cells.Add(tempCell);
//string tt=((TextBox)FindControl("T"+i+"M"+j)).Text.Trim();
  string tt1=((TextBox)FindControl("T2M1")).Text.Trim();
   Table3.Rows.Add(tempRow); }
程序就像上面那样!
//string tt=((TextBox)FindControl("T"+i+"M"+j)).Text.Trim();
  string tt1=((TextBox)FindControl("T2M1")).Text.Trim();
我上面两句不知道错在那里?都提示:未将对象引用设置到对象的实例。小弟不知道问题在那?我是想取得某个TextBox里的值.请高手帮忙!

解决方案 »

  1.   

    string tt1=((TextBox)from1.FindControl("T2M1")).Text.Trim();
      

  2.   

    string tt1=((TextBox)FindControl("T2M1")).Text.Trim();
    放到Table3.Rows.Add(tempRow);应该就可以了,控件没有加入到集合中
      

  3.   

    ytq2080() 我单步调试了。myddl.ID="T2M2"有啊。jsyhello(不认输) 我是B/S的,不是C/S的。不能用from1吧?wangkun9999(西洋樱草,我的生日花,大家不要误解哟) 我是动态加载的,

    string tt1=myddl.Text.Trim();这样不知道到底是取那个值啊!
    ice_frank(NULL) 不明白你的意思!