代码示例1:
dlist = New System.Web.UI.WebControls.DropDownList()
dlist.Items.Clear()
dlist.ID = "d" & rs2.Fields("zdm").Value
Do While Not rs3.EOF
dlist.Items.Add(rs3.Fields(0).Value)
rs3.MoveNext()
Loop
td2.Controls.Add(dlist)
代码示例2:
TextBox textbox = new TextBox();
textbox.ID = showReader.GetValue(0).ToString();
this.Controls.Add(textbox);
代码示例3:
// 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, null);
// Initialize the item from the template.
ItemTemplate.InstantiateIn(item);
// Add the item to the ControlCollection.
Controls.Add(item);
}
}
}
备注
新控件添加到序号索引数组的末尾。控件可以是任何 ASP.NET 服务器控件、您创建的自定义服务器控件或文本控件的实例。
若要将控件添加到集合中的特定索引位置,请使用 AddAt 方法。