Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
ITemplate Interface
ITemplate Methods
 InstantiateIn Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
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)
Visual Basic (Declaration)
Sub InstantiateIn ( _
    container As Control _
)
Visual Basic (Usage)
Dim instance As ITemplate
Dim container As Control

instance.InstantiateIn(container)
C#
void InstantiateIn(
    Control container
)
Visual C++
void InstantiateIn(
    Control^ container
)
JScript
function InstantiateIn(
    container : 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.

Visual Basic
' 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 

C#
// 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 void InstantiateIn(Control container)
{
    Literal l = new Literal();
    l.DataBinding += new EventHandler(this.BindData);
    container.Controls.Add(l);
}
// Create a public method that will handle the
// DataBinding event called in the InstantiateIn method.
public void BindData(object sender, EventArgs e)
{
    Literal l = (Literal) sender;
    DataGridItem container = (DataGridItem) l.NamingContainer;
    l.Text = ((DataRowView) container.DataItem)[column].ToString();

}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
More on dynamic templating      AnonymousToday   |   Edit   |   Show History
If you're looking for a complete example, as I was, on creating a dynamic template and seem to think that something is missing head on over to http://msdn.microsoft.com/en-us/library/0e39s2ck.aspx as it will explain how to implement this and other items. With these two examples dynamic templates may be possible.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker