[英]How do I export an asp:FormView ItemTemplate to an external file
I have an asp:FormView like this: 我有一个像这样的asp:FormView:
<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?
我怎样才能做到这一点?
Extract the code you have in the templates and add them to separate .ascx
files. 提取模板中包含的代码,并将其添加到单独的
.ascx
文件中。 Then you can do this: 然后,您可以执行以下操作:
ASPX 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");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.