Pregunta

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?

¿Fue útil?

Solución

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");
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top