Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
What is this page about?
This page explains how to work with content controls conceptually and programmatically.
LINQ Reporting Engine enables you to perform certain operations on content controls dynamically while building a report.
Note – To work with content controls in template documents using Microsoft Word®, you may need to show the Developer tab on its ribbon.
You can set checkbox values to either checked or unchecked in your reports dynamically by taking the following steps:
check tag to the title of the checkbox content control using the following syntax.<<check [conditional_expression]>>
Here, conditional_expression defines a condition upon which the value of the checkbox content control is to be set to checked (or unchecked, if the condition is not met). The conditional expression must return a Boolean value.
While building a report, a conditional expression declared within a check tag is evaluated and the value of its containing checkbox content control is set accordingly. The check tag itself is removed then.
You can dynamically add items to comboboxes and dropdown lists defined in your template by taking the following steps:
<<item [value_expression] [display_name_expression]>>
Here, value_expression defines a value of a combobox or dropdown list item to be added dynamically. This expression is mandatory and must return a non‑empty value.
In turn, display_name_expression defines a display name of the combobox or dropdown list item to be added. This expression is optional. If it is omitted, then during runtime, a value of value_expression is used as a display name as well.
Note – Values of both value_expression and display_name_expression can be of any types. During runtime, Object.ToString() is invoked to get textual representations of these expressions’ values.
While building a report, value_expression and display_name_expression are evaluated and a corresponding combobox or dropdown list item is added. A declaring item tag is removed then.
A single item tag causes addition of a single combobox or dropdown list item during runtime. You can add multiple combobox or dropdown list items using multiple item tags as shown in the following snippet.
<<item ...>><<item ...>>
Also, you can normally use item tags within data bands to add a combobox or dropdown list item per item of a data collection. For example, given that clients is a DataTable instance having a field named “Name”, you can use the following template to cover such a scenario.
<<foreach [client in clients]>><<item [client.Name]>><</foreach>>
An item tag can also be combined with an if tag to add a combobox or dropdown list item depending on a condition as shown in the following snippet.
<<if ...>><<item ...>><</if>>
Existing combobox and dropdown list items are not affected by item tags. Thus, you can combine both ways of adding combobox and dropdown list items using a template: static and dynamic.
Note – While inserting a combobox or dropdown list, Microsoft Word adds a default item that has to be removed manually, if the item is unwanted.
You can normally use common expression tags in content control titles, thus forming their contents dynamically. For example, given that s is a string value, you can set a content control title from this value dynamically by putting the following expression tag into the title.
<<[s]>>
Q: How do I make a checkbox content control checked or unchecked based on data?
A: Add a check tag to the checkbox title using the syntax <<check [conditional_expression]>>. The expression must return a Boolean value; if true, the checkbox is checked, otherwise it remains unchecked. The check tag is removed automatically after evaluation.
Q: What is the correct way to add items to a combobox or dropdown list at runtime?
A: Use the item tag inside the content control title: <<item [value_expression] [display_name_expression]>>. The first argument supplies the item value (required), and the optional second argument supplies the display text. Multiple item tags can be placed sequentially or generated inside a foreach loop.
Q: Can I conditionally add a combobox item only when a certain condition is met?
A: Yes. Wrap the item tag inside an if tag, e.g., <<if [condition]>> <<item [value]>> <</if>>. The item will be added only if the condition evaluates to true.
Q: Why does a default item appear in a newly inserted dropdown list, and how can I remove it?
A: Microsoft Word automatically inserts a placeholder item when a dropdown list is created. This item is not removed by Aspose.Words, so you must delete it manually in the template or programmatically after the document is generated.
Q: How can I set the title of a content control dynamically using a variable?
A: Place an expression tag inside the title, such as <<[myVariable]>>. During report generation the variable’s ToString() value replaces the tag, producing a dynamic title. This works for any content control type.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.