SIGN UP MEMBER LOGIN:    
ARTICLE

Show Images in Reports at Run-time using ReportViewer

Posted by Abhijeet Lakra Articles | Visual Studio .NET May 11, 2009
This article shows how to put Images in Reports created using ReportViewer dynamically.
Reader Level:

Query: How to put Images in Reports (Microsoft ReportViewer) through code at runtime/dynamically?

You can achieve this with charm. You can easily have images on your report, even the images that are on the Web.

Assumption:

This article assumes that a user has basic idea about RDLC, Microsoft ReportViewer and DataSource. This Article does not teach the basics of how to generate Reports in Microsoft Report Viewer.

To learn about ReportViewer and how to build reports, read this free book by Mahesh Chand:
Reports using Report Viewer in Visual Studio 2005.


In ReportViewer, you have 2 options for images: External or Embedded.

1.
Embedded:

If you have images in your application and you want to use them.

Stage I: Then, you first need to embed the images in to be used in Reports. To embed an image in Reports:
a) Open the RDLC File.
b) Go to the Menu Item:
Report > Embedded Images. Click on: New Image.
c) Browse for the image. Edit
Name for the image chosen as desired (example, here: TestImage). OK.

Stage II:
d) Use an Image control on your RDLC file.
e) Set the
Image's Property-Source = Embedded.
f) Reserve a Report's DataSource Member for the image Path. For example- DataSource.ImgPath.
g) Set the value for image path from the code in
DataSource.ImgPath.
    For example: DataSource.ImgPath = "TestImage";
h) Do the normal stuff to bind DataSource etc.
i) Done. Enjoy your image in the Report.



2.
External:

If you do not have images in your Application. That is, you want to use an external image.

a. Use an Image control on your RDLC file.
b. Set the
Image's Property-Source = External.
c. Reserve a Report's DataSource Member for the image Path. For example- DataSource.ImgPath.
d. Set the value for image path from the code in
DataSource.ImgPath.
    For example: DataSource.ImgPath = "http://www.google.com/intl/en_ALL/images/logo.gif";
e. The following self explanatory code also needs to be written:
    reportViewer1.LocalReport.EnableExternalImages = true;  (reportViewer1 is the Name for the   ReportViewer Control)
f. Do the normal stuff to bind DataSource etc.
g. Done. Enjoy your image in the Report.

 
 

Login to add your contents and source code to this article
share this article :
post comment
 

I do not display a field of type Image in MicrosoftReport know how I should set the DataSource. My image is stored in a database field of type Image. Please help me.

Posted by SAM SAM Feb 29, 2012

u are really advance thanks man

Posted by vanitha Dec 22, 2011

I follow your instruction for option 1 embedded image. It doesn't work. Can you explain detail about step f f) Reserve a Report's DataSource Member for the image Path. For example- DataSource.ImgPath. g) Set the value for image path from the code in DataSource.ImgPath. For example: DataSource.ImgPath = "TestImage"; I created user defined class ReportMasterData with one string attribute imgPath. string imgPath; I set the value inside my code all other attribute can be displayed on the report (like text field) but the image not show.

Posted by dd ss Dec 16, 2010
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor