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)

void InstantiateIn (
	Control container
)
void InstantiateIn (
	Control container
)
function InstantiateIn (
	container : Control
)
Not applicable.

Parameters

container

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 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();
    
}

// 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.add_DataBinding(new EventHandler(this.BindData));
    container.get_Controls().Add(l);
} //InstantiateIn

// 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.get_NamingContainer();
    l.set_Text(((DataRowView)container.get_DataItem()).
        get_Item(column).ToString());
} //BindData 

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft