Layout data cannot find data for DataName of RecordBox

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v11)  /  Layout data cannot find data for DataName of RecordBox

DynamicPDF CoreSuite for .NET (v11) Forum

I have been trying to get my RecordBoxes to populate with data from a List.  I have drilled it down to the point of using purely hardcoded data so that there is no room for error on the data being populated, yet the RecordBox still fails to populate.

Here is the code that I'm trying to run:

DocumentLayout layout = new DocumentLayout(projectDirectory + "\\report.dlex");
LayoutData layoutData = new LayoutData();
List<CashAdvance> exampleData = new List<CashAdvance>()
            {
                new CashAdvance {
                    BranchName = "Test Branch",
                    BusinessDate = "02/06/2023",
                    SequenceNum = "4",
                    Amount = "5000.00",
                    TransactionDate = "02/04/2023"
                },
                new CashAdvance
                {
                    BranchName = "Test Branch",
                    BusinessDate = "02/06/2023",
                    SequenceNum = "5",
                    Amount = "5000.00",
                    TransactionDate = "02/04/2023"
                }
            };
layoutData.Add("PreparedFor", "Author");
layoutData.Add("CashAdvances", exampleData);
Document doc = layout.Layout(layoutData);
doc.Draw(projectDirectory + "\\test.pdf");

The .dlex file template contains RecordBoxes that are suppose to display the data of within each CashAdvance object.  However, I'm getting an exception every time I try to build the document stating "Layout data for BranchName could not be retrieved because data by that name doesn't exist." 

If I debug down into LayoutData, I can see that it has the List with all entries and properties, but it claims it does not exist.  I have tried many different ways of referencing the data, but when I do everything according to how the LayoutData documentation states, it still does not work.

If I reference "PreparedFor" as the DataName, it prints out the value as expected, however, any reference to the CashAdvances list fails.

I have read the documentation multiple times and cannot figure out what I'm doing wrong.  Any guidance on what to use for the DataName in order to display the properties of each item in the list would be greatly appreciated.
Posted by a ceTe Software moderator
Hi,

You probably just need to set your report's DataName property to "CashAdvances". If you have that set, you'll be able to access the BranchName and other properties in the Detail section of the report and it will repeat once for each object in the list. If you continue to have issues, please send the DLEX to support@dynamicpdf.com and we'll let you know what we find.

Thanks,
ceTe Software Support Team
To bind a list of objects to a RecordBox or other elements in your .dlex template, you need to ensure that the data structure in your LayoutData object matches the template's structure. In your case, you want to populate data for multiple CashAdvance objects within your template.

Assuming that your .dlex template has a RecordBox that should display the properties of each CashAdvance object, you can structure your LayoutData as follows:
DocumentLayout layout = new DocumentLayout(projectDirectory + "\\report.dlex");
LayoutData layoutData = new LayoutData();

// Add the preparedFor data
layoutData.Add("PreparedFor", "Author");

// Create a list to hold the data for CashAdvances
List<Dictionary<string, string>> cashAdvancesData = new List<Dictionary<string, string>>();

// Iterate through your exampleData and add each CashAdvance's properties to a dictionary
foreach (CashAdvance cashAdvance in exampleData)
{
    Dictionary<string, string> cashAdvanceDict = new Dictionary<string, string>
    {
        { "BranchName", cashAdvance.BranchName },
        { "BusinessDate", cashAdvance.BusinessDate },
        { "SequenceNum", cashAdvance.SequenceNum },
        { "Amount", cashAdvance.Amount },
        { "TransactionDate", cashAdvance.TransactionDate }
    };
    
    cashAdvancesData.Add(cashAdvanceDict);
}

// Add the list of dictionaries to the LayoutData under the name "CashAdvances"
layoutData.Add("CashAdvances", cashAdvancesData);

// Now, layout your document
Document doc = layout.Layout(layoutData);
doc.Draw(projectDirectory + "\\test.pdf");


In this code, we convert each CashAdvance object into a dictionary with keys corresponding to the property names. We then add these dictionaries to a list, which is added to the LayoutData object with the name "CashAdvances." This should align with how your .dlex template is structured to accept a list of dictionaries for rendering RecordBoxes.

All times are US Eastern Standard time. The time now is 3:57 PM.