Asp. Dynamic loading of template in net

Source: Internet
Author: User
Asp. NET, often use the templates (template) features, such as in Datagrid,datalist,repeater and other controls, the use of templates, will greatly enhance its functionality. In the past, when we were designing a program, we had already set the template in the control. However, sometimes, we may need to dynamically load templates, for example, when you ask your application's interface style to change with the user's needs, you need to go to the dynamic Loading template function. Note, however, that not all Web controls support the template feature, and note which controls support the functionality of the template, and some of the controls that support the template feature are listed below:
Repeater control, supported templates are:
HeaderTemplate, FooterTemplate, ItemTemplate, AlternatingItemTemplate, Seperatortemplate.
Datelist control, supported templates are:
HeaderTemplate, FooterTemplate, ItemTemplate, AlternatingItemTemplate, SeparatorTemplate, SelectedItemTemplate, EditItemTemplate.
The DataGrid control, supported templates are:
HeaderTemplate, FooterTemplate, ItemTemplate, EditItemTemplate, Pager.
Below, I'll show you how to dynamically load a template by dynamically loading the template for the DataList control:
The first step is to understand the principle of dynamic loading templates. In. NET, there is the TemplateControl class, which is the base class for page and UserControl classes. It also defines the basic functions of page and UserControl classes. This class provides two methods: LoadControl and LoadTemplate. The LoadControl method loads the control from the external file and returns the UserControl class object. The LoadTemplate method loads the template from the external file and returns the ITemplate object.
In the LoadTemplate method, there is only one parameter, the parameter value is the path to the external template file, and the ITemplate object is returned. The DataList control provides a series of properties that allow you to set properties for various templates, including AlternatingItemTemplate, EditItemTemplate, FooterTemplate, HeaderTemplate, ItemTemplate, SelectedItemTemplate, and Seperatortemplate, in the following section, will see the relevant introduction.
Zmbbs=1;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.