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;