We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Setting check boxes in table from data

How would I check/uncheck a box in a table row depending on the mailmerge data?

I am currently using ExecuteWithRegions(SqlDataReader) to build the table, but the customer wants to see checkboxes rather than a simple mailmerge field.


Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I think that you can use MergeField event handler for this. For example see the following code and attached documents.

public void Test263()


//Create some datasource

DataTable table = new DataTable("myTable");



table.Columns.Add("IsAdmin", typeof(bool));

//Add some data

table.Rows.Add(new object[] { "1", "Alexey", true});

table.Rows.Add(new object[] { "2", "Andrey", false });

//Open template

Document doc = new Document(@"Test263\in.doc");

//Add MergeField event handler

doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField263);

//Execute mail merge


//Save document



void MailMerge_MergeField263(object sender, MergeFieldEventArgs e)


if (e.FieldName == "IsAdmin")


//create document builder

DocumentBuilder builder = new DocumentBuilder(e.Document);

//Move to field

builder.MoveToField(e.Field, true);

//Insert checkbox (name will be unique for each formfield)

builder.InsertCheckBox(e.Field.GetHashCode().ToString(), (bool)e.FieldValue, 10);

e.Text = string.Empty;



Hope this helps.

Best regards.

OK, didn't realise I had to insert them rather than simply checking existing ones in the template.

Works fine