我的代码是这样写的
string lastcontent = ((TextBox)Repeater1.FindControl("msg_lastcontent")).ToString();
报错提示:未将对象引用设置到对象的实例。
请问这条语句应该怎样改????
string lastcontent = ((TextBox)Repeater1.FindControl("msg_lastcontent")).ToString();
报错提示:未将对象引用设置到对象的实例。
请问这条语句应该怎样改????
{
TextBox p=item.FindControl("msg_lastcontent") as TextBox ;
if(p!=null)
{
string lastcontent =p.Text ;
}
}
1.不能直接用Repeater1.FindControl ,可以用Repeater1.Item[i].FindControl()2.(TextBox)Repeater1.FindControl("msg_lastcontent")
这句即使你获得到数据 ,它也是textbox
不可直接tostring()
{
Repeater rpt = (Repeater)e.Item.FindControl("rptSamll");
if ((Label)e.Item.FindControl("lblBigID") is Label)
{
Label LblBigID=(Label)e.Item.FindControl("lblBigID");
}
}
这个是获取Label的你改成TextBox就行了。