Dynamic template loading in ASP. NET

Source: Internet
Author: User

In ASP. NET, the templates (Template) function is often used, for example, in the datagrid, datalist, repeater and other controls, the use of templates will greatly enhance its function. In the past, we generally set the template in the control when designing the program. However, sometimes, we may need to dynamically load templates. For example, when you want your application's interface style to change with your needs, you need the function of dynamically loading templates. However, it should be noted that not all web controls support the template function. Also, note which controls support the template function. The following lists some controls that support the template function:
The Repeater control supports the following templates:
HeaderTemplate, FooterTemplate, ItemTemplate, AlternatingItemTemplate, SeperatorTemplate.
Datelist control. Supported Templates include:
HeaderTemplate, FooterTemplate, ItemTemplate, AlternatingItemTemplate, SeparatorTemplate, SelectedItemTemplate, EditItemTemplate.
Datagrid Control. Supported Templates include:
HeaderTemplate, FooterTemplate, ItemTemplate, EditItemTemplate, Pager.
Next, I will use a template to dynamically load the datalist control to illustrate how to dynamically load the template:
First, let's understand the principle of dynamic loading templates. In. NET, there is a templatecontrol class, which is the base class of the page and usercontrol classes. It also defines the basic functions of the page and usercontrol classes. This class provides two methods: loadcontrol and loadtemplate. The Loadcontrol method loads controls from external files and returns the usercontrol class object. The loadtemplate method loads the template from an external file and returns the Itemplate object.
In the Loadtemplate method, there is only one parameter. The parameter value is the path of the external template file and the itemplate object is returned. The datalist control provides a series of attributes that can be used to set attributes of various templates, including AlternatingItemTemplate, EditItemTemplate, FooterTemplate, HeaderTemplate, ItemTemplate, SelectedItemTemplate, and SeperatorTemplate, you will see the introduction.
Zmbbs = 1;

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.