C# can';在FormView中找不到控件?
我需要找到这个C# can';在FormView中找不到控件?,c#,asp.net,formview,findcontrol,C#,Asp.net,Formview,Findcontrol,我需要找到这个 我尝试了fvMediaIntro.FindControl()和fvMediaIntro.Row.FindControl(),都没有成功。 有什么想法吗?FindControl只有在创建这些控件之后,即当数据绑定到FormView时,才会起作用。因此,您需要在FormView等或DataBound上使用适当的事件。比如说, protected void fvMediaIntro_ItemCreated(Object sender, EventArgs e) { var co
我尝试了fvMediaIntro.FindControl()
和fvMediaIntro.Row.FindControl()
,都没有成功。
有什么想法吗?
FindControl
只有在创建这些控件之后,即当数据绑定到FormView
时,才会起作用。因此,您需要在FormView
等或DataBound
上使用适当的事件。比如说,
protected void fvMediaIntro_ItemCreated(Object sender, EventArgs e)
{
var control = fvMediaIntro.Row.FindControl("iNeedToFindThis") as HtmlAnchor;
}
假设您在
page\u load
中绑定或使用标记,您还可以使用父页面/控件的prerender
事件安全地执行FindControl
我可以迭代Formview中的所有行吗?@PankajGarg,我不确定您所说的所有行是什么意思!FormView一次只显示一个数据行-可通过行
属性访问该数据行。其他行对象可能基于设置而存在,例如HeaderRow
、FooterRow
、TopPagerRow
等
protected void fvMediaIntro_ItemCreated(Object sender, EventArgs e)
{
var control = fvMediaIntro.Row.FindControl("iNeedToFindThis") as HtmlAnchor;
}