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;
}