Access a control inside a the LayoutTemplate of a ListView

craigmoliver picture craigmoliver · Jan 11, 2009 · Viewed 40.2k times · Source

How do I access a Control in the LayoutTemplate of a ListView control?

I need to get to litControlTitle and set its Text attribute.

<asp:ListView ID="lv" runat="server">
  <LayoutTemplate>
    <asp:Literal ID="litControlTitle" runat="server" />
    <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
  </LayoutTemplate>
  <ItemTemplate>
  </ItemTemplate>
</asp:ListView>

Any thoughts? Perhaps via the OnLayoutCreated event?

Answer

tanathos picture tanathos · Jan 11, 2009

Try this:

((Literal)lv.FindControl("litControlTitle")).Text = "Your text";