Export (0) Print
Expand All

ITemplate.InstantiateIn Method

When implemented by a class, defines the Control object that child controls and templates belong to. These child controls are in turn defined within an inline template.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

'Declaration
Sub InstantiateIn ( _
	container As Control _
)

Parameters

container
Type: System.Web.UI.Control

The Control object to contain the instances of controls from the inline template.

When developing templated server controls, you do not need to implement this method; the .NET Framework provides the implementation for you.

' Override the ITemplate.InstantiateIn method to ensure  
' that the templates are created in a Literal control and 
' that the Literal object's DataBinding event is associated 
' with the BindData method. 
Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
   Dim l As New Literal()
   AddHandler l.DataBinding, AddressOf Me.BindData
   container.Controls.Add(l)
End Sub 'InstantiateIn

' Create a public method that will handle the 
' DataBinding event called in the InstantiateIn method. 
Public Sub BindData(sender As Object, e As EventArgs)
   Dim l As Literal = CType(sender, Literal)
   Dim container As DataGridItem = CType(l.NamingContainer, DataGridItem)
   l.Text = CType(container.DataItem, DataRowView)(column).ToString()
End Sub 'BindData 

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
Show:
© 2015 Microsoft