Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
TemplateGroupCollection Class
Collapse the table of content
Expand the table of content

TemplateGroupCollection Class

Represents a collection of TemplateGroup objects within a control designer. This class cannot be inherited.


Namespace:  System.Web.UI.Design
Assembly:  System.Design (in System.Design.dll)

public sealed class TemplateGroupCollection : IList, 
	ICollection, IEnumerable

The TemplateGroupCollection type exposes the following members.

Public methodTemplateGroupCollectionInitializes a new instance of the TemplateGroupCollection class.

Public propertyCountGets the number of TemplateGroup objects in the collection.
Public propertyItemGets or sets a TemplateGroup object at the specified index in the collection.

Public methodAddAdds the specified TemplateGroup object to the end of the collection.
Public methodAddRangeAdds the template groups in an existing TemplateGroupCollection object to the current TemplateGroupCollection object.
Public methodClearRemoves all groups from the collection.
Public methodContainsDetermines whether the specified group is contained within the collection.
Public methodCopyToCopies the groups in the collection to a compatible one-dimensional array, starting at the specified index of the target array.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIndexOfReturns the index of the specified TemplateGroup object within the collection.
Public methodInsertInserts a TemplateGroup object into the collection at the specified index.
Public methodRemoveRemoves the specified TemplateGroup object from the collection.
Public methodRemoveAtRemoves the TemplateGroup object at the specified index within the collection.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Public Extension MethodAsParallel()Overloaded. Enables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsParallel()Overloaded. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryable()Overloaded. Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodAsQueryable()Overloaded. (Defined by Queryable.)
Public Extension MethodCast<TResult>()Overloaded. Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodCast<TResult>()Overloaded. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>()Overloaded. Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>()Overloaded. (Defined by Enumerable.)

Explicit interface implemetationPrivate methodICollection.CopyToInfrastructure. For a description of this member, see CopyTo.
Explicit interface implemetationPrivate propertyICollection.CountInfrastructure. For a description of this member, see Count.
Explicit interface implemetationPrivate propertyICollection.IsSynchronizedInfrastructure. For a description of this member, see IsSynchronized.
Explicit interface implemetationPrivate propertyICollection.SyncRootInfrastructure. For a description of this member, see SyncRoot.
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorInfrastructure. For a description of this member, see GetEnumerator.
Explicit interface implemetationPrivate methodIList.AddInfrastructure. For a description of this member, see Add.
Explicit interface implemetationPrivate methodIList.ClearInfrastructure. For a description of this member, see Clear.
Explicit interface implemetationPrivate methodIList.ContainsInfrastructure. For a description of this member, see Contains.
Explicit interface implemetationPrivate methodIList.IndexOfInfrastructure. For a description of this member, see IndexOf.
Explicit interface implemetationPrivate methodIList.InsertInfrastructure. For a description of this member, see Insert.
Explicit interface implemetationPrivate propertyIList.IsFixedSizeInfrastructure. For a description of this member, see IsFixedSize.
Explicit interface implemetationPrivate propertyIList.IsReadOnlyInfrastructure. For a description of this member, see IsReadOnly.
Explicit interface implemetationPrivate propertyIList.ItemInfrastructure. For a description of this member, see the IList class.
Explicit interface implemetationPrivate methodIList.RemoveInfrastructure. For a description of this member, see Remove.
Explicit interface implemetationPrivate methodIList.RemoveAtInfrastructure. For a description of this member, see RemoveAt.

The ControlDesigner class, and any derived class, defines the TemplateGroups property as a TemplateGroupCollection object. The TemplateGroupCollection property is typically used only by a design host such as Visual Studio 2005.

The collection dynamically increases in size as objects are added. Indexes in this collection are zero-based. Use the Count property to determine how many groups are in the collection.

Additionally, use the TemplateGroupCollection methods and properties to provide the following functionality:

  • The Add method to add a single group to the collection.

  • The Insert method to add a group at a particular index within the collection.

  • The Remove method to remove a group.

  • The RemoveAt method to remove the group at a particular index.

  • The Contains method to determine whether a particular group is already in the collection.

  • The IndexOf method to retrieve the index of a group within the collection.

  • The Item indexer to get or set the group at a particular index, using array notation.

  • The AddRange method to add multiple groups to the collection.

    You can add multiple groups either as an array of groups or as a TemplateGroupCollection object that you retrieve through the TemplateGroups property of another control designer.

  • The Clear method to remove all groups from the collection.

The following code example demonstrates how to define a simple control designer that is derived from the ControlDesigner class. The derived control designer implements the TemplateGroups property by getting the template groups that are defined for the base class and adding a template group that is specific to the derived control designer.

using System;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace Examples.AspNet
    // Define a simple control designer that adds a 
    // template group to the template group collection. 
    class DerivedControlDesigner : System.Web.UI.Design.ControlDesigner
        private DerivedControl internalControl = null;

        private const String templateGroupName = "My template group";
        private const String templateDefinitionName1 = "First";
        private const String templateDefinitionName2 = "Second";
        private TemplateGroup internalGroup = null;

        // Override the read-only TemplateGroups property. 
        // Get the base group collection, and add a group  
        // with two template definitions for the derived 
        // control designer. 
        public override TemplateGroupCollection TemplateGroups
                // Start with the groups defined by the base designer class.
                TemplateGroupCollection groups = base.TemplateGroups;

                if (internalGroup == null) 
                    // Define a new group with two template definitions.
                    internalGroup = new TemplateGroup(templateGroupName, 

                    TemplateDefinition templateDef1 = new TemplateDefinition(this, 
                        templateDefinitionName1, internalControl, 
                        templateDefinitionName1, internalControl.ControlStyle);

                    TemplateDefinition templateDef2 = new TemplateDefinition(this, 
                        templateDefinitionName2, internalControl, 
                        templateDefinitionName2, internalControl.ControlStyle);


                // Add the new template group to the collection.

                return groups;


    // Define a simple web control, and associate it with the designer.
    public class DerivedControl : WebControl
        // Define derived control behavior here.


.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2015 Microsoft