As mentioned above, expressions in brackets can be used within the Text property of RenderText and ParagraphText objects. In those expressions, the following object IDs are available:
This variable references the document being generated. This can be used in a number of ways, for instance the following code will print the author of the current document:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim doc As New C1PrintDocument() Dim rt As New RenderText("Landscape is " + _ "[Iif(Page.PageSettings.Landscape,\"TRUE\",\"FALSE\")].") doc.Body.Children.Add(rt) |
To write code in C#
C# |
Copy Code
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); RenderText rt = new RenderText("Landscape is " + "[Iif(Page.PageSettings.Landscape,\"TRUE\",\"FALSE\")]."); doc.Body.Children.Add(rt); |
This variable references the current render object. For instance, the following code will print the name of the current render object:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim doc As New C1PrintDocument() Dim rt As New RenderText( _ "The object's name is [RenderObject.Name]") rt.Name = "MyRenderText" doc.Body.Children.Add(rt) |
To write code in C#
C# |
Copy Code
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); RenderText rt = new RenderText( "The object's name is [RenderObject.Name]"); rt.Name = "MyRenderText"; doc.Body.Children.Add(rt); |
This variable references the current page (object of type C1Page). While the most commonly used in scripts members of the page object are accessible directly (see PageNo, PageCount and so on below), there is other data that can be accessed via the Page variable, such as the current page settings. For instance, the following code will print "Landscape is TRUE" if the current page layout has landscape orientation, and "Landscape is FALSE" otherwise:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim doc As New C1PrintDocument() Dim rt As New RenderText("Landscape is " + _ "[Iif(Page.PageSettings.Landscape,\"TRUE\",\"FALSE\")].") doc.Body.Children.Add(rt) |
To write code in C#
C# |
Copy Code
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); RenderText rt = new RenderText("Landscape is " + "[Iif(Page.PageSettings.Landscape,\"TRUE\",\"FALSE\")]."); doc.Body.Children.Add(rt); |
This name resolves to the current 1-based page number. Equivalent to Page.PageNo.
This name resolves to the total page count for the document. Equivalent to Page.PageCount. For instance, the following code can be used to generate the common "Page X of Y" page header:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim doc As New C1PrintDocument() doc.PageLayout.PageHeader = New RenderText( _ "Page [PageNo] of [PageCount]") |
To write code in C#
C# |
Copy Code
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); doc.PageLayout.PageHeader = new RenderText( "Page [PageNo] of [PageCount]"); |
This name resolves to the current 1-based horizontal page number. (For documents without horizontal page breaks, will return 1.)
This name resolves to the current 1-based vertical page number. (For documents without horizontal page breaks, will be equivalent to PageNo.)
This name resolves to the total page count for the document. (For documents without horizontal page breaks, will return 1.)
This name resolves to the total page count for the document. (For documents without horizontal page breaks, will be equivalent to PageCount.)
It is important to note that any of page numbering-related variables described here can be used anywhere in a document not necessarily in page headers or footers.
This variable references the collection of available database fields, and has the type C1.C1Preview.DataBinding.FieldCollection. It can only be used in data-bound documents. For instance, the following code will print the list of product names contained in the Products table of the NWIND database:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim doc As New C1PrintDocument() Dim dSrc As New DataSource() dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB dSrc.ConnectionProperties.ConnectString = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C1NWIND.MDB" Dim dSet1 As New C1.C1Preview.DataBinding.DataSet( _ dSrc, "select * from Products") doc.DataSchema.DataSources.Add(dSrc) doc.DataSchema.DataSets.Add(dSet1) Dim rt As New RenderText() rt.DataBinding.DataSource = dSet1 rt.Text = "[Fields!ProductName.Value]" doc.Body.Children.Add(rt) |
To write code in C#
C# |
Copy Code
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); DataSource dSrc = new DataSource(); dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB; dSrc.ConnectionProperties.ConnectString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C1NWIND.MDB"; C1.C1Preview.DataBinding.DataSet dSet1 = new C1.C1Preview.DataBinding.DataSet(dSrc, "select * from Products"); doc.DataSchema.DataSources.Add(dSrc); doc.DataSchema.DataSets.Add(dSet1); RenderText rt = new RenderText(); doc.Body.Children.Add(rt); rt.DataBinding.DataSource = dSet1; rt.Text = "[Fields!ProductName.Value]"; |
Note the use of "!" to access an element of the fields array in the last line. Alternatively, you can write:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
rt.Text = "[Fields(\"ProductName\").Value]" |
To write code in C#
C# |
Copy Code
|
---|---|
rt.Text = "[Fields(\"ProductName\").Value]"; |
but the notation using "!" is shorter and easier to read.
This variable allows access to the collection of aggregates defined on the document. That collection is of the type C1.C1Preview.DataBinding.AggregateCollection, its elements have the type C1.C1Preview.DataBinding.Aggregate. For instance, the following code will print the average unit price after the list of products:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim doc As New C1PrintDocument() Dim dSrc As New DataSource() dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB dSrc.ConnectionProperties.ConnectString = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C1NWIND.MDB" C1.C1Preview.DataBinding.DataSet dSet1 = _ new C1.C1Preview.DataBinding.DataSet(dSrc, _ "select * from Products") doc.DataSchema.DataSources.Add(dSrc) doc.DataSchema.DataSets.Add(dSet1) Dim rt As New RenderText() doc.Body.Children.Add(rt) rt.DataBinding.DataSource = dSet1 rt.Text = "[Fields!ProductName.Value]" doc.DataSchema.Aggregates.Add(new Aggregate( _ "AveragePrice", "Fields!UnitPrice.Value", _ rt.DataBinding, RunningEnum.Document, _ AggregateFuncEnum.Average)) doc.Body.Children.Add(new RenderText( _ "Average price: [Aggregates!AveragePrice.Value]")) |
To write code in C#
C# |
Copy Code
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); DataSource dSrc = new DataSource(); dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB; dSrc.ConnectionProperties.ConnectString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C1NWIND.MDB"; C1.C1Preview.DataBinding.DataSet dSet1 = new C1.C1Preview.DataBinding.DataSet(dSrc, "select * from Products"); doc.DataSchema.DataSources.Add(dSrc); doc.DataSchema.DataSets.Add(dSet1); RenderText rt = new RenderText(); doc.Body.Children.Add(rt); rt.DataBinding.DataSource = dSet1; rt.Text = "[Fields!ProductName.Value]"; doc.DataSchema.Aggregates.Add(new Aggregate( "AveragePrice", "Fields!UnitPrice.Value", rt.DataBinding, RunningEnum.Document, AggregateFuncEnum.Average)); doc.Body.Children.Add(new RenderText( "Average price: [Aggregates!AveragePrice.Value]")); |
This variable allows accessing the DataBinding property of the current render object, of the type C1.C1Preview.DataBinding.C1DataBinding. For instance, the following code (modified from the sample showing the use of Fields variable) will produce a numbered list of products using the RowNumber member of the render object's DataBinding property in the text expression:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim doc As New C1PrintDocument() Dim dSrc As New DataSource() dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB dSrc.ConnectionProperties.ConnectString = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C1NWIND.MDB" C1.C1Preview.DataBinding.DataSet dSet1 = _ new C1.C1Preview.DataBinding.DataSet(dSrc, _ "select * from Products") doc.DataSchema.DataSources.Add(dSrc) doc.DataSchema.DataSets.Add(dSet1) Dim rt As New RenderText() rt.DataBinding.DataSource = dSet1 rt.Text = "[DataBinding.RowNumber]: [Fields!ProductName.Value]" doc.Body.Children.Add(rt) |
To write code in C#
C# |
Copy Code
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); DataSource dSrc = new DataSource(); dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB; dSrc.ConnectionProperties.ConnectString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C1NWIND.MDB"; C1.C1Preview.DataBinding.DataSet dSet1 = new C1.C1Preview.DataBinding.DataSet(dSrc, "select * from Products"); doc.DataSchema.DataSources.Add(dSrc); doc.DataSchema.DataSets.Add(dSet1); RenderText rt = new RenderText(); rt.DataBinding.DataSource = dSet1; rt.Text = "[DataBinding.RowNumber]: [Fields!ProductName.Value]"; doc.Body.Children.Add(rt); |