本文整理汇总了C#中System.Web.UI.Control.ChildControlsCreated属性的典型用法代码示例。如果您正苦于以下问题:C# Control.ChildControlsCreated属性的具体用法?C# Control.ChildControlsCreated怎么用?C# Control.ChildControlsCreated使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Web.UI.Control
的用法示例。
在下文中一共展示了Control.ChildControlsCreated属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddParsedSubObject
//引入命名空间
using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TemplateControlSamples
{
[ParseChildren(true)]
public class CustomRepeater : Repeater
{
// Override to prevent LiteralControls from being added as children.
protected override void AddParsedSubObject(object o)
{
}
// Override to create repeated items.
protected override void CreateChildControls()
{
object o = ViewState["NumItems"];
if (o != null)
{
// Clear any existing child controls.
Controls.Clear();
int numItems = (int)o;
for (int i = 0; i < numItems; i++)
{
// Create an item.
RepeaterItem item = new RepeaterItem(i, ListItemType.Item);
// Initialize the item from the template.
ItemTemplate.InstantiateIn(item);
// Add the item to the ControlCollection.
Controls.Add(item);
}
}
}
// Override to create the repeated items from the DataSource.
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
if (DataSource != null)
{
// Iterate over an ICollection DataSource, creating a new item for each data item.
IEnumerator dataEnum = ((ICollection)base.DataSource).GetEnumerator();
int i = 0;
while (dataEnum.MoveNext())
{
// Create an item.
RepeaterItem item = new RepeaterItem(i, ListItemType.Item);
item.DataItem = dataEnum.Current;
// Initialize the item from the template.
ItemTemplate.InstantiateIn(this);
// Add the item to the ControlCollection.
Controls.Add(item);
i++;
}
// Prevent child controls from being created again.
ChildControlsCreated = true;
// Store the number of items created in view state for postback scenarios.
ViewState["NumItems"] = i;
}
}
}
}