LINQ Reporting Engine, how to setup values into a drop down list Control of Microsoft Word (Developer Mode)

so in Word → Developer tab →
we can add Drop-Down List Content Control
Then we can set drop down items
see screenshot:

Now I have LINQ Reporting Engine, with same values
such as

<<[Text1]>>
<<[Text2]>>

Is that possible to set up into that drop down list Control?

@zhenyu.wang

You can populate a Drop‑Down List Content Control in a Word template that is later processed by the LINQ Reporting Engine, but the engine itself cannot create the list items – they must exist in the document before the report is executed.

Typical workflow

  1. Create the drop‑down list in the template (or add it programmatically before the report runs).
  2. Give the control a tag (e.g. DropDown1). The tag is the field name that the LINQ Reporting Engine will bind to.
  3. Run the LINQ Reporting Engine – it will set the selected value of the control based on the data source.

1. Add the list items with DocumentBuilder

using Aspose.Words;
using Aspose.Words.BuildingBlocks;
using Aspose.Words.Markup;

// load a blank template or an existing .docx
Document doc = new Document("Template.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a drop‑down list content control
StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.DropDownList, MarkupLevel.Block);
sdt.Tag = "DropDown1";               // <-- this tag is used by LINQ Reporting Engine
sdt.Title = "Select an option";

// Add the list items
sdt.ListItems.Add(new ListItem("Item A", "A"));
sdt.ListItems.Add(new ListItem("Item B", "B"));
sdt.ListItems.Add(new ListItem("Item C", "C"));

// Place the control where you need it
builder.InsertNode(sdt);
builder.Writeln();   // optional line break after the control

doc.Save("TemplateWithDropDown.docx");

Result: TemplateWithDropDown.docx now contains a drop‑down list with three items and a tag DropDown1.

2. LINQ Reporting Engine – set the selected value

using Aspose.Words.Reporting;
using System.Collections.Generic;

// data source – the property name must match the tag of the control
var data = new
{
    DropDown1 = "B"   // value that matches one of the ListItem values ("A","B","C")
};

ReportingEngine engine = new ReportingEngine();
engine.BuildReport("TemplateWithDropDown.docx", "Result.docx", data);

When the report is built, the drop‑down list will show Item B as the selected entry.

What you cannot do with the LINQ Reporting Engine

  • Dynamically add or remove list items at run‑time.
  • Populate the list from a collection directly – the list must be defined in the template (or added with DocumentBuilder before BuildReport is called).

If you need the list items to be generated from a data source, create the control programmatically before invoking the reporting engine, e.g.:

var items = GetItemsFromDatabase();   // returns IEnumerable<KeyValuePair<string,string>>
foreach (var kvp in items)
    sdt.ListItems.Add(new ListItem(kvp.Key, kvp.Value));

Then run the LINQ Reporting Engine as shown above to set the selected value.


Next steps / checks

  • Verify you are using a recent version of Aspose.Words for .NET (the API shown works from v20.9 onward).
  • Ensure the tag name in the template (DropDown1 in the example) exactly matches the property name in the data object passed to BuildReport.

If you still encounter issues, please provide:

  • Aspose.Words version you are using.
  • A minimal template (or the part of the template that contains the control).
  • The exact code you use to invoke the LINQ Reporting Engine.

With that information we can pinpoint any version‑specific quirks.

1 Like

thank you for details suggestions
will have a try later

@zhenyu.wang Please see our documentation to lean how to add items to dropdown dynamically:
https://docs.aspose.com/words/net/working-with-content-controls/#adding-combobox-and-dropdown-list-items-dynamically

1 Like