C# 从代码隐藏访问formView页脚模板内的userControl
我有以下代码:C# 从代码隐藏访问formView页脚模板内的userControl,c#,asp.net,user-controls,devexpress,formview,C#,Asp.net,User Controls,Devexpress,Formview,我有以下代码: <asp:FormView runat="server"> <ItemTemplate> </ItemTemplate> <FooterTemplate> <div> <hr/> <uc1:Footer runat="server" ID="Footer" />
<asp:FormView runat="server">
<ItemTemplate>
</ItemTemplate>
<FooterTemplate>
<div>
<hr/>
<uc1:Footer runat="server" ID="Footer" />
</div>
</FooterTemplate>
</asp:FormView>
在Footer.ascx中,我有:
<dx:ASPxLabel ID="lbl" runat="server" Font-Italic="True" Font-Size="10px"></dx:ASPxLabel>
我想从代码隐藏中访问我的用户控件页脚详细信息以设置lbl值
我怎么能这样做呢
谢谢 首先,您需要提供一个属性,该属性返回
UserControl
的标签,或者更好的是返回文本。然后,您可以使用FormView
和FindControl
获取它:
var uc = (UserControlTypeName)FormView1.FooterRow.FindControl("Footer");
uc.Value = "New Value";
以下是用户控件中的属性:
public string Value
{
get { return lbl.Text; }
set { lbl.Text = value; }
}
感谢您的回复,但对我来说FormView1.FooterRow是null@Nabila:是FooterRow
还是FooterRow.FindControl(“页脚”)
null?通常,此属性在FormView.ItemCreated
中/之后设置。因此,如果您尝试更早地访问它(例如从Page\u Init
或Page\u Load
),它将为空。解决方案是稍后访问它(例如,在FormView
的itemscreated
或itemsdatabound
或页面的PreRender
)。