This project has moved and is read-only. For the latest updates, please go here.

Build your First Report

Step 0 – Choose a data source for the report

In many projects will use your existing LINQ queries as the report's data source. These queries are great candidates to quickly turn them into DoddleReports. You can also use DataTables or even SharePoint lists, so please see Key Components for more examples of IReportSource that come packaged with DoddleReport.

For this example, we will create a simple ProductRepository that generates 1000 random products.

public static class ProductRepository
    public static List<Product> GetAll()
        var rand = new Random();
        return Enumerable.Range(1, 1000)
            .Select(i => new Product
                                    Id = i,
                                    Name = "Product " + i,
                                    Description =
                                        "This is an example description showing long text in some of the items, now I am just rambling",
                                    Price = rand.NextDouble()*100,
                                    OrderCount = rand.Next(1000),
                                    LastPurchase = DateTime.Now.AddDays(rand.Next(1000)),
                                    UnitsInStock = rand.Next(0, 2000)


Step 1 – Create a new Report() and pass it your IReportSource

DoddleReport ships with a helpful ToReportSource() extension method on IEnumerable and DataTable to easily turn the underlying data into a report source that DoddleReport can understand.

// Get the data for the report (any IEnumerable or LINQ query will work)
var query = ProductRepository.GetAll();

// Create the report and turn our query into a ReportSource
var report = new Report(query.ToReportSource());

Step 2 – Customize the report TextFields, RenderHints, and DataFields

While this step is entirely optional, it’s a good idea to fill in some basic info. Please see the Advanced Customization Page to get a better idea for report customization possibilities

// Customize the Text Fields
report.TextFields.Title = "Products Report";
report.TextFields.SubTitle = "This is a sample report showing how Doddle Report works";
report.TextFields.Footer = "Copyright 2011 &copy; The Doddle Project";
report.TextFields.Header = string.Format(@"
    Report Generated: {0}
    Total Products: {1}
    Total Orders: {2}
    Total Sales: {3:c}", DateTime.Now, totalProducts, totalOrders, totalProducts * totalOrders);

// Render hints allow you to pass additional hints to the reports as they are being rendered
report.RenderHints.BooleanCheckboxes = true;

// Customize the data fields
report.DataFields["Id"].Hidden = true;
report.DataFields["Price"].DataFormatString = "{0:c}";
report.DataFields["LastPurchase"].DataFormatString = "{0:d}";

Step 3a – Pick a Report Writer (IReportWriter)

The IReportWriter is what writes the Report to a Stream in a specific format, like Excel, HTML, or PDF.

In some cases you want to choose the ReportWriter manually (described in this step), but if you are using ASP.NET be sure to read Step 3b!

Please see Key Components to see what report writers come packaged with DoddleReport

var writer = new HtmlReportWriter();
writer.WriteReport(report, HttpContext.Response.OutputStream);

Step 3b – Web Reporting from ASP.NET

If you are using ASP.NET / MVC be sure to read the Web Reporting section, which describes some much easier ways to integrate DoddleReport into your ASP.NET applications

Last edited Jan 14, 2012 at 5:23 PM by mhidinger, version 7


talleyouro May 21, 2015 at 8:48 PM