Reports for WinForms | ComponentOne
Working with C1PrintDocument / Expressions, Scripts, Tags / Tags
In This Topic
    Tags
    In This Topic

    Tags are closely related to expressions. In fact, tags are variables that can be used in expressions, or simply as expressions. In the simplest case, tags allow you to use a placeholder where you want to insert a certain string but do not know the value of that string yet. The typical example of a tag is the page number- you want to print the page number but do not know yet what it is going to be or realize it may change when the document is regenerated.

    A tag has two main properties: Name and Value. The name is used to identify the tag, while the value is what the tag is replaced with.

    C1PrintDocument provides two kinds of tags: predefined and custom. Predefined tags are:

    Custom tags are stored in the Tags collection of the document. To add a tag to that collection, you may use the following code:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    doc.Tags.Add(New C1.C1Preview.Tag("tag1", "tag value"))
    

    To write code in C#

    C#
    Copy Code
    doc.Tags.Add(new C1.C1Preview.Tag("tag1", "tag value"));
    

    The value of the tag may be left unspecified when the tag is created, and may be specified at some point later (even after that tag was used in the document).

    To use a tag, insert its name in square brackets in the text where you want the tag value to appear, for example, like this:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim rt As New C1.C1Preview.RenderText()
    rt.Text = "The value of tag1 will appear here: [tag1]."
    

    To write code in C#

    C#
    Copy Code
    RenderText rt = new RenderText();
    rt.Text = "The value of tag1 will appear here: [tag1].";