Search code examples
c#asp.netformviewitemtemplate

ASP.net access control in FormView ItemTemplate


I have a form view with an item template with a control inside, is it possible to access that control OnDatabound so I can bind the control with data. I'm using a panel as an example here.

<cc1:LOEDFormView ID="FireFormView" runat="server" DataSourceID="DataSourceResults"     CssClass="EditForm" DataKeyNames="id" OnDatabound="FireFromView_Databound">
<ItemTemplate>

<asp:Panel ID ="pnl" runat="server"></asp:Panel>

</ItemTemplate>

</cc1:LOEDFormView>

Solution

  • You have to take care the item mode as well in which your control exist which you want to find. Like if your control in Item Template, then it would be like..

    if (FormView1.CurrentMode == FormViewMode.ReadOnly)
    {
    
      Panel pnl = (Panel)FormView1.FindControl("pnl");
    }