ASP.net access control in FormView ItemTemplate

Funky picture Funky · May 5, 2011 · Viewed 16.5k times · Source

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>

Answer

Muhammad Akhtar picture Muhammad Akhtar · May 5, 2011

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