Dynamicweb 8 Documentation
TagCollection Class
Members  Example 

Represents a collection of Tag.
Object Model
TagCollection ClassTag Class
Syntax
Example
Working with tags and tagcollectionWorking with tags and tagcollection
using Dynamicweb.Rendering;

namespace Dynamicweb.Examples.CSharp.Rendering
{
    public class TagSample
    {

        public static void AddTags(Template t)
        {
            //Create a tag instance and add it to a template instance
            var myTag = new Tag("greeting", "Hello");
            t.Tags.Add(myTag);
            //Create a second tag instance using its Name and Value properties and add it to a template instance
            var myTag2 = new Tag();
            myTag2.Name = "greeting2";
            myTag2.Value = " World!";
            t.Tags.Add(myTag2);

            //Create a collection of tags and add it to a template instance
            var myTags = new TagCollection();
            for (int i = 1; i <= 5; i++)
            {
                myTags.Add(new Tag("Counter" + i.ToString(), i.ToString()));
            }
            t.Tags.Add(myTags);

            //Examine all the tags in the template instance.
            foreach (Tag tag in t.Tags)
            {
                if (tag.Name == "greeting")
                {
                    //Found the tag in the collection named "greeting"
                }
            }

            //Or look it up
            if (t.Tags.ContainsTagName("greeting"))
            {
                //Found the tag in the collection named "greeting"
            }

            //And clear all tags from the template instances tags collection
            t.Tags.Clear();
        }
    }
}
Imports Dynamicweb.Rendering

Public Class TagSample
    Public Shared Sub AddTags(ByVal t As Template)

        'Create a tag instance and add it to a template instance
        Dim myTag As New Tag("greeting", "Hello")
        t.Tags.Add(myTag)

        'Create a second tag instance using its Name and Value properties and add it to a template instance
        Dim myTag2 As New Tag()
        myTag2.Name = "greeting2"
        myTag2.Value = " World!"
        t.Tags.Add(myTag2)

        'Create a collection of tags and add it to a template instance
        Dim myTags As New TagCollection
        For i As Integer = 1 To 5
            myTags.Add(New Tag("Counter" & i.ToString(), i.ToString()))
        Next
        t.Tags.Add(myTags)

        'Examine all the tags in the template instance.
        For Each tag As Tag In t.Tags
            If tag.Name = "greeting" Then
                'Found the tag in the collection named "greeting"
            End If
        Next

        'Or look it up
        If t.Tags.ContainsTagName("greeting") Then
            'Found the tag in the collection named "greeting"
        End If

        'And clear all tags from the template instances tags collection
        t.Tags.Clear()
    End Sub
End Class
Inheritance Hierarchy

System.Object
   System.Collections.ObjectModel.Collection<T>
      System.Collections.ObjectModel.KeyedCollection<TKey,TItem>
         Dynamicweb.Rendering.TagCollection

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

TagCollection Members
Dynamicweb.Rendering Namespace

Send Feedback