Creating default templates on Repeater that are overridable by users
I have a webforms control, my:Repeater, that is an asp:Repeater. I want to make a default template, like:
<my:Repeater>
<HeaderTemplate>
My Default Header
</HeaderTemplate>
<ItemTemplate>
开发者_开发知识库My data
</ItemTemplate>
<FooterTemplate>
My Default Footer
</FooterTemplate>
</my:Repeater>
I want this template to be in some file not writable by the user. If the user just do
<my:Repeater/>
then it should use my default template. However, the user may override one or more of <HeaderTemplate>
, <ItemTemplate>
or <FooterTemplate>
.
Is this possible, and how can I achieve it?
Each template is an ITemplate; you can programmably create a template through code by implementing ITemplate and programmably adding controls to the parent container. In OnInit method, you could setup the default templates, and if the user supplies an ItemTemplate, it, theoretically, should override your template.
精彩评论