This is a migrated thread and some comments may be shown as answers.

How to bind a datatable to a reportviewer in mvc

1 Answer 337 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
muhammed
Top achievements
Rank 1
muhammed asked on 20 Feb 2018, 10:39 AM

I have a reporting library project with MVC what I am trying to do is bind the data table to the report viewer and display it my MVC page as I am newbie Telerik what is the best way to display the data table in the viewer by using fields

 

public DataTable data()
       {
           DataTable table = new DataTable();
           DataRow dr = table.NewRow();
           dr["Name"] = "Lion";
           dr["Type"] = "Mammal";
           table.Rows.Add(dr);
           return table;
       }
       public DataTable Getdata()
       {
           var d1 = data();
           return d1;
       }
@(Html.TelerikReporting().ReportViewer()
       // Each report viewer must have an id - it will be used by the initialization script
       // to find the element and initialize the report viewer.
       .Id("reportViewer1")
       // The URL of the service which will serve reports.
       // The URL corresponds to the name of the controller class (ReportsController).
       // For more information on how to configure the service please check http://www.telerik.com/help/reporting/telerik-reporting-rest-conception.html.
       .ServiceUrl(Url.Content("/api/reports"))
        // The URL for custom report viewer template. The template can be edited -
        // new functionalities can be added and unneeded ones can be removed.
        // For more information please check http://www.telerik.com/help/reporting/html5-report-viewer-templates.html.
        // .TemplateUrl(Url.Content("/ReportViewer/templates/telerikReportViewerTemplate-10.1.16.615.html"))
        // Strongly typed ReportSource - TypeReportSource or UriReportSource.
        .ReportSource(new TypeReportSource() { TypeName = typeof(ReportLibrary1.Databinding.Report1).AssemblyQualifiedName })
       // Specifies whether the viewer is in interactive or print preview mode.
       // PrintPreview - Displays the paginated report as if it is printed on paper. Interactivity is not enabled.
       // Interactive - Displays the report in its original width and height with no paging. Additionally interactivity is enabled.
       .ViewMode(ViewMode.Interactive)
       // Sets the scale mode of the viewer.
       // Three modes exist currently:
       // FitPage - The whole report will fit on the page (will zoom in or out), regardless of its width and height.
       // FitPageWidth - The report will be zoomed in or out so that the width of the screen and the width of the report match.
       // Specific - Uses the scale to zoom in and out the report.
       .ScaleMode(ScaleMode.Specific)
       // Zoom in and out the report using the scale
       // 1.0 is equal to 100%, i.e. the original size of the report
       .Scale(1.0)
       // Sets whether the viewer’s client session to be persisted between the page’s refreshes(ex. postback).
       // The session is stored in the browser’s sessionStorage and is available for the duration of the page session.
       .PersistSession(false)
       // Sets the print mode of the viewer.
       .PrintMode(PrintMode.AutoSelect)
   )

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 23 Feb 2018, 04:28 PM
Hi muhammed,

The Html5 Report Viewer is just a widget used to display the reports.

The Data is related to the Report and its data items, not to the Report Viewer.
The data items in the report definition are connected to data sources through Data Source Components.

You can use an ObjectDataSource component to supply your Report (or Table/List/Graph etc) with data, and configure it to get the data from the DataTable.

Regards,
Todor
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
muhammed
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or