我的代码是这样写的
string lastcontent = ((TextBox)Repeater1.FindControl("msg_lastcontent")).ToString();
报错提示:未将对象引用设置到对象的实例。 
请问这条语句应该怎样改????

解决方案 »

  1.   

                    foreach(RepeaterItem item Repeater1.Items)
                    {
                        TextBox p=item.FindControl("msg_lastcontent") as TextBox ;
                        if(p!=null)
                        {
                         string lastcontent =p.Text ;
                        }
                    }
      

  2.   

    你的代码有两处错误:
    1.不能直接用Repeater1.FindControl ,可以用Repeater1.Item[i].FindControl()2.(TextBox)Repeater1.FindControl("msg_lastcontent")
      这句即使你获得到数据 ,它也是textbox
      不可直接tostring()
      

  3.   

    一般来说,对于容器控件都是FindControl找控件啊
      

  4.   

    if ((Repeater)e.Item.FindControl("rptSamll") is Repeater)
            {
                Repeater rpt = (Repeater)e.Item.FindControl("rptSamll");   
                if ((Label)e.Item.FindControl("lblBigID") is Label)
                {
                    Label LblBigID=(Label)e.Item.FindControl("lblBigID");
                } 
            }    
    这个是获取Label的你改成TextBox就行了。