2

I have an asp:FormView like this:

<asp:FormView ID="foo" runat="server" >
    <ItemTemplate>
      ... lots of code
    </ItemTemplate>
    <EditItemTemplate>
      ... lots more code
    </EditItemTemplate>
<asp:FormView>

I would like to move the templates out to separate files, if possible. How can I do this?

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
ConditionRacer
  • 4,418
  • 6
  • 45
  • 67

1 Answers1

1

Extract the code you have in the templates and add them to separate .ascx files. Then you can do this:

ASPX

<asp:FormView ID="foo" runat="server" OnInit="foo_Init">

Code behind

protected void foo_Init(object sender, EventArgs e)
{
    foo.ItemTemplate = Page.LoadTemplate("~/Controls/MyLayoutTemplate.ascx");
    foo.EditTemplate = Page.LoadTemplate("~/Controls/MyEditTemplate.ascx");
}
Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480