SpriteHand
Module Border
  ReportViewer control - programmatically
Module Border
Location: BlogsAndy's Blog    
Posted by: host 1/26/2006 9:08 AM
In VS2005, the report designer is great for quickly throwing together a report and binding it to an ObjectDataSource... but what if you want to do this through code for more control?
 
The steps are to create the report _without_ using a TableAdapter, and then manually create the data source through code (below). Note that the "rds.Name" property must be set to the "DataSetName" attribute in the report's RSDL file:
         <DataSetName>DSCustomers_OutCustomersDataSetName>

Dim dsCustomers As DSCustomers
Dim oCustomers As New CCustomers()

dsCustomers = oCustomers.GetCustomers()
Dim rds As ReportDataSource = New ReportDataSource
ReportViewer1.LocalReport.DataSources.Clear()
rds.Name =
"DSCustomers_OutCustomers"
rds.Value = dsCustomers.OutCustomers
ReportViewer1.LocalReport.DataSources.Add(rds)
ReportViewer1.DataBind()


As a second example, let's say you use a Typed DataSet and TableAdapter as a Data Source and you are creating a WindowsForms application. In the example below, a Typed DataSet has been created called "DataSet1" which queries the Customers table.

Some important things to remember:

  • you need to call  the Reset() method on the ReportViewer whenever you dynamically switch reports.
  • you need to prefix report (RDLC) filenames with the Namespace of the project the report is in (below the namespace is "ReportViewerTest.")

reportViewer1.Reset();

DataSet1TableAdapters.CustomersTableAdapter ta1 = new DataSet1TableAdapters.CustomersTableAdapter();

DataSet1.CustomersDataTable dt1 = new DataSet1.CustomersDataTable();

ta1.Fill(dt1);

 

ReportDataSource rds = new ReportDataSource();

reportViewer1.LocalReport.DataSources.Clear();

reportViewer1.LocalReport.ReportEmbeddedResource = "ReportViewerTest.Report1.rdlc";

rds.Name = "DataSet1_Customers";

rds.Value = dt1;

reportViewer1.LocalReport.DataSources.Add(rds);

reportViewer1.RefreshReport();

 

 

 

Permalink |  Trackback

Comments (5)   Add Comment
Re: ReportViewer control - programmatically    By Anonymous on 3/16/2006 12:48 PM
Thank you soooo much for this! You saved me many hours of hair-pulling! :-)

Re: ReportViewer control - programmatically    By Anonymous on 3/6/2009 12:28 PM
Awsome! Exactly what I needed.

Re: ReportViewer control - programmatically    By Anonymous on 1/9/2010 1:28 AM
where does reportViewer1 get instantiated?

Re: ReportViewer control - programmatically    By Anonymous on 4/6/2010 5:18 AM
Thanx!

After several hours trying, this code was the key to programmatically create PDF-files on the fly.

Regards // Eric Jexén

Re: ReportViewer control - programmatically    By Anonymous on 4/12/2010 10:45 AM
Andy, you are a lifesaver! Thank you very much.


Title:
Comment:
Add Comment   Cancel 
Module Border Module Border
Module Border
  Subscribe
Module Border
RSS   Twitter
Module Border Module Border
Module Border
  Diversions
Module Border

TALKING RAGDOLL
This Windows Phone 7 App was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine. It gets interesting when you import your friends photos and have your way with them!

MORE INFO



DROPPYPOP
This Windows Phone 7 game was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine.
DEMO

MORE INFO



BOSS LAUNCH
This physics game won first place in the Server Quest Contest. Created using Silverlight 2, the Physics Helper Library,  and the Farseer Physics Engine.
PLAY IT

MORE INFO



DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight 2.
PLAY IT

INFO AND CODE



PHYSICS HELPER DEMOS
These demos were created for the Physics Helper Library, which makes it easy to create physics games and simulations using Expression Blend, Silverlight, and the Farseer Physics Engine.
PLAY IT

INFO AND CODE



HOOK SHOT
This little basketball game took first place in the TeamZoneSports Silverlight Contest. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight 2.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2013 andy.beaulieu.com - Login