Loading reportviewer through an object

Asked

Viewed 398 times

2

I am using Report Viewer to do some reports, but I am not able to access some data from my object. instead of making a direct connection to the database I pass a Datatable as a reference, and in Reportviewer I add a Dataset Object. This is the following structure used:

class Produto{
    public int Codigo{get;set}
    public string NomeProduto {get;set;}
    public Categoria Cat {get;set;}
}

class Categoria{
    public int Codigo{get;set}
    public string NomeCategoria{get;set;}
}

In Reportviewer I have normal access to the Product Code and Product Name but cannot access the items of my Category object ... I use the expression =Fields!Codigo.Value to Retrieve Product Code and in Expression Fields an option appears with Category First(Fields!Categoria.Value, "Data") but even if I put it it does not carry anything, I wonder how it is possible to carry the name of the Category, for example First(Fields!(Categoria.NomeCategoria).Value, "Data")

1 answer

1

Just associate Dataset to your Table in Report (Attributes must have the same name), and pass the list modelList to the DataSource:

LocalReport relatorio = new LocalReport();
relatorio.DataSources.Add(new ReportDataSource("DSTituloProjetado", modelList));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.