TemplateControl.LoadTemplate Method
.NET Framework 3.0
Obtains an instance of the ITemplate interface from an external file.
Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
'Declaration Public Function LoadTemplate ( _ virtualPath As String _ ) As ITemplate 'Usage Dim instance As TemplateControl Dim virtualPath As String Dim returnValue As ITemplate returnValue = instance.LoadTemplate(virtualPath)
public ITemplate LoadTemplate ( String virtualPath )
public function LoadTemplate ( virtualPath : String ) : ITemplate
Not applicable.
Parameters
- virtualPath
The virtual path to a user control file.
Return Value
An instance of the specified template.The following code example demonstrates how to use the LoadTemplate method to add a user control as an alternating item to a DataList Web server control named DataList1. The user control implements the ITemplate interface and is contained in a file named Newtemplate.ascx.
Sub Page_Load(sender As [Object], e As EventArgs) If Not IsPostBack Then DataList1.AlternatingItemTemplate = LoadTemplate("newtemplate.ascx") DataList1.DataSource = CreateDataSource() DataList1.DataBind() End If End Sub 'Page_Load
void Page_Load(Object sender, System.EventArgs e)
{
if (!(get_IsPostBack())) {
DataList1.set_AlternatingItemTemplate(
LoadTemplate("newtemplate.ascx"));
DataList1.set_DataSource(CreateDataSource());
DataList1.DataBind();
}
}//Page_Load
Community Additions
ADD
Show: