How to: Create Parameter
The following example demonstrates how to create the report parameter in the Snap Report API.
- Call the IRichEditDocumentServer.LoadDocumentTemplate method to load the document template and open it for modification by calling the SubDocument.BeginUpdate method.
- Create a new Parameter instance that is the new report parameter.
- To set the parameter’s name, type and value, use the Parameter.Name, Parameter.Type and Parameter.Value properties.
- Add the created object to the document’s parameters collection, accessible through the SnapDocument.Parameters property.
- Finalize the modification by calling the SubDocument.EndUpdate method.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/snap-document-server-api-t429162
server.LoadDocumentTemplate("Template.snx")
server.Document.BeginUpdate()
'Create parameter:
Dim param1 As New Parameter()
param1.Name = "Region"
param1.Type = GetType(System.String)
param1.Value = "NEW ENGLAND"
server.Document.Parameters.Add(param1)
'Insert parameter field in the document:
Dim list As SnapList = server.Document.FindListByName("Data Source 11")
server.Document.ParseField(list.Field)
list.BeginUpdate()
list.ListHeader.InsertText(list.ListHeader.Tables(0).FirstRow.Cells.InsertAfter(3).ContentRange.End, "Region")
list.RowTemplate.CreateSnText(list.RowTemplate.Tables(0).FirstRow.Cells.InsertAfter(3).ContentRange.End, "Region \p")
list.Field.Update()
list.EndUpdate()
server.Document.EndUpdate()
server.Document.Fields.Update()