DropDownList.CreateControlCollection Method ()
.NET Framework (current version)
Creates a collection to store child controls.
Assembly: System.Web (in System.Web.dll)
The following code example demonstrates how to override the CreateControlCollection method in a custom server control so that it always returns a new instance of the EmptyControlCollection class for the DropDownList control. For information about using custom server controls, see Walkthrough: Developing and Using a Custom Web Server Control.
<%@ Page Language="VB" AutoEventWireup="True" %> <%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Custom DropDownList - CreateControlCollection - VB.NET Example</title> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) DropDownList1.Items.Add(New ListItem("Item1", "Item1")) DropDownList1.Items.Add(New ListItem("Item2", "Item2")) DropDownList1.Items.Add(New ListItem("Item2", "Item2")) End Sub </script> </head> <body> <form id="Form1" method="post" runat="server"> <h3>Custom DropDownList - CreateControlCollection - VB.NET Example</h3> <aspSample:CustomDropDownListCreateControlCollection id="DropDownList1" runat="server" /> </form> </body> </html>
Imports System.Web Imports System.Security.Permissions Namespace Samples.AspNet.VB.Controls <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _ Public NotInheritable Class CustomDropDownListCreateControlCollection Inherits System.Web.UI.WebControls.DropDownList Protected Overrides Function CreateControlCollection() As System.Web.UI.ControlCollection ' Return a new EmptyControlCollection Return New System.Web.UI.EmptyControlCollection(Me) End Function End Class End Namespace
.NET Framework
Available since 1.1
Available since 1.1
Show: