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
)。