Dynamically Add and Display External Image in RDLC Report From Code Behind in ASP

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Dynamically add and display external Image in RDLC Report from code behind in ASP.Net http://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.

aspx

Home
Categories

1 of 11 18/01/2016 2:44 PM
Dynamically add and display external Image in RDLC Report from code behind in ASP.Net http://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx

2 of 11 18/01/2016 2:44 PM
Dynamically add and display external Image in RDLC Report from code behind in ASP.Net http://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx

3 of 11 18/01/2016 2:44 PM
Dynamically add and display external Image in RDLC Report from code behind in ASP.Net http://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx

Forums
Contact

Search

15 May 2014 Mudassar Khan


10 Comments 43563 Views
ASP.Net RDLC Report

Here Mudassar Ahmed Khan has explained how to show external images to RDLC Report in ASP.Net.
The path of the external image will be dynamically set from code behind using Report parameter.

Download View Demo

Don't forget to download Aspose as well: http://aspose.com/file-tools

4 of 11 18/01/2016 2:44 PM
Dynamically add and display external Image in RDLC Report from code behind in ASP.Net http://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx

Like 10k Follow @ASPSnippets 1.3k

In this article I will explain how to show external images to RDLC Report in ASP.Net. The path of the external image will be dynamically set from code behind using Report parameter.

Configuring the RDLC Report


1. I have already added a blank RDLC Report and an Image to the Solution folder.

2. Now add a Parameter to the RDLC Report of type text and set its name.

5 of 11 18/01/2016 2:44 PM
Dynamically add and display external Image in RDLC Report from code behind in ASP.Net http://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx

3. Insert an Image on to the RDLC Report.

Set its name, ToolTip to be displayed and make sure you select the Image Source as External. Next we need to set the following formula which means that path of the image will be fetched from the ImagePath Report Parameter we have added in step
#2.

=Parameters!ImagePath.Value

Then in the Size Tab you need to set the Display property as Original Size.

Once image gets added you should see as below.

6 of 11 18/01/2016 2:44 PM
Dynamically add and display external Image in RDLC Report from code behind in ASP.Net http://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx

HTML Markup
The HTML Markup consists of ASP.Net ScriptManager and ReportViewer control.

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"


Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server">
</rsweb:ReportViewer>
</form>
</body>
</html>

Namespaces
You will need to import the following namespaces.
C#

using Microsoft.Reporting.WebForms;

VB.Net

Imports Microsoft.Reporting.WebForms

Display external image in RDLC Report


In the below code, first thing I am setting the Report Path and then the most important property EnableExternalImages has to be set to True, otherwise the image will not be shown.
Finally we need to convert the image path to File Uri and then pass as value to the ImagePath Report Parameter and pass it to the RDLC Report.
C#

protected void Page_Load(object sender, EventArgs e)


{
if (!this.IsPostBack)

7 of 11 18/01/2016 2:44 PM
Dynamically add and display external Image in RDLC Report from code behind in ASP.Net http://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx

{
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
ReportViewer1.LocalReport.EnableExternalImages = true;
string imagePath = new Uri(Server.MapPath("~/images/Mudassar.jpg")).AbsoluteUri;
ReportParameter parameter = new ReportParameter("ImagePath", imagePath);
ReportViewer1.LocalReport.SetParameters(parameter);
ReportViewer1.LocalReport.Refresh();
}
}

VB.Net

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load


If Not Me.IsPostBack Then
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc")
ReportViewer1.LocalReport.EnableExternalImages = True
Dim imagePath As String = New Uri(Server.MapPath("~/images/Mudassar.jpg")).AbsoluteUri
Dim parameter As New ReportParameter("ImagePath", imagePath)
ReportViewer1.LocalReport.SetParameters(parameter)
ReportViewer1.LocalReport.Refresh()
End If
End Sub

Once you execute the application you should be able to view the external image in RDLC Report as shown below.

Image not visible and Cross Image appears in RDLC Report

Now in spite of following all steps if you still do not see the report and you see a cross image icon on the RDLC Report, then you need to follow the following procedure.
You will need to make sure that either both or one of the following Handlers are added to the Web.Config file.
1. Add the following to <system.web> => <httpHandlers> section.

<add verb = "*" path = "Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, Publ
icKeyToken=b03f5f7f11d50a3a" />

8 of 11 18/01/2016 2:44 PM
Dynamically add and display external Image in RDLC Report from code behind in ASP.Net http://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx

2. Add the following to <system.webServer> => <handlers> section.

<add name = "ReportViewerWebControlHandler" preCondition = "integratedMode" verb = "*" path = "Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler, M
icrosoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

Note: If you don’t have both sections in your Web.Config then you can add only to the one you have.

Demo

View Demo

Downloads
Download

FAQ: Dynamically Adding Rows in ASP Table on Button Click event


Here Vinz has explained how to add rows to Table dynamically on button click in ASP.Net link rellast titleExcel like AutoFilter Feature in ASP.Net GridView Control
Tip Pass table name dynamically to SQL Server query or stored procedure
Here Mudassar Ahmed Khan has explained how to dynamically pass table name to SQL Query or Stored Procedure in SQL Server 2000 2005 2008
Adjust width of ASP.Net DropDownList (HTML SELECT) dynamically using JavaScript
Here Mudassar Ahmed Khan has explained how to dynamically adjust the width of the ASP.Net DropDownList (HTML SELECT) based on the text length of the largest item or option using JavaScript
Adjust width of ASP.Net DropDownList (HTML SELECT) dynamically using jQuery
Here Mudassar Ahmed Khan has explained how to dynamically adjust the width of the ASP.Net DropDownList (HTML SELECT) based on the text length of the largest item or option using jQuery
Dynamically freeze ASP.Net Gridview header using JavaScript
Here Mudassar Ahmed Khan has explained how to dynamically freeze header or make the header fixed of ASP.Net GridView control using JavaScript. This is a cross browser solution and works in all new browsers
including Internet Explorer 8 (IE8) Chrome FireFox Opera and Safari. This is a unique solution where you dont need to do anything the script will automatically convert your GridView to a scrollable grid with fixed headers
ASP.Net AJAX AutoCompleteExtender: Dynamically set ContextKey using JavaScript
Here Mudassar Ahmed Khan has explained how to dynamically set value of ContextKey for ASP.Net AJAX Control ToolKit AutocompleteExtender using JavaScript
Dynamically load and display ASP.Net UserControl using jQuery AJAX and WebMethod
Here Mudassar Ahmed Khan has explained how to dynamically load ASP.Net UserControl using jQuery AJAX and Web Service WebMethods. He has also explained how we can set values of Controls and Properties of the
UserControl before loading it.
Dynamically Generate and Display Barcode Image in ASP.Net
Here Mudassar Ahmed Khan has explained how to build a barcode generator in ASP.Net using C# and VB.Net which will dynamically generate and display Barcode Image in ASP.Net Image control.
Dynamically change (switch) CSS file programmatically from code behind in ASP.Net
Here Mudassar Ahmed Khan has explained with an example and attached sample code, how to Dynamically change or switch CSS file programmatically from code behind in ASP.Net using C# and VB.Net
Dynamically change GridView Row Background Color based on condition in ASP.Net using C# and VB.Net
Here Mudassar Ahmed Khan has explained with an example and attached sample code, how to dynamically change the Background color of ASP.Net GridView Row based on some conditions in program code using C#
and VB.Net.
Dynamically add meta tags in ASP.Net
Here Mudassar Ahmed Khan has explained, how to dynamically add meta tags in ASP.Net Website. The dynamic meta tags will be populated from database and each meta tag will be added dynamically to head section of
page.
Dynamically create DataTable and bind to GridView in ASP.Net
Here Mudassar Ahmed Khan has explained, how to dynamically (programmatically) at runtime create a DataTable using C# or VB.Net and then bind it to GridView in ASP.Net. First a dynamic DataTable object is created and
its schema (Table structure and Columns) is defined programmatically. Once the columns are defined, then rows (records) are added to the dynamically generated DataTable. Once the dynamic DataTable is populated with
records, it is bound to an ASP.Net GridView control.
Create DataTable dynamically and bind to GridView in ASP.Net
Here Mudassar Ahmed Khan has explained, how to dynamically create DataTable and bind to GridView in ASP.Net using C# and VB.Net
Dynamically add BoundField and TemplateField Columns to GridView in ASP.Net
Here Mudassar Ahmed Khan has explained, how to dynamically add BoundField and TemplateField column to GridView in ASP.Net using C# and VB.Net. Dynamic BoundField and TemplateField columns will be created and
then added to GridView after that the GridView will be populated from database. At runtime using the OnRowDataBound event of GridView, controls like TextBox, Button, etc. will be added to the Dynamic TemplateField
columns. This article also covers the problem of dynamic columns disappearing on PostBack and describes the necessary solution to retain the dynamic columns on PostBack. Finally this article explains how to handle click
events of dynamic Button, LinkButton or ImageButton that will be added to the dynamic TemplateField columns and also explains how to fetch values from the dynamic BoundField and TemplateField columns when thee

9 of 11 18/01/2016 2:44 PM
Dynamically add and display external Image in RDLC Report from code behind in ASP.Net http://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx

Buttons are clicked.


Add BoundField Column dynamically to GridView in ASP.Net
Here Mudassar Ahmed Khan has explained, how to dynamically add BoundField and TemplateField column to GridView in ASP.Net using C# and VB.Net.

Talal Aug 27, 2014 02:08 PM 193.188.86.103


Thanks
its nice code

Abas Abdullahi Ali Sep 13, 2014 07:09 PM 41.78.73.5


thank you thank you
it was so so good and it helped me
thank you guys for help

Joisman JimnezSep 16, 2014 04:09 AM 190.67.235.41


Nice work

AhmadMar 15, 2015 04:03 PM 103.243.179.146


Thank you very much Mudasser khan

It is very nice post.

Eduardo SierraApr 07, 2015 10:04 AM 200.118.16.142


Great code. Thanks.

More

You can add your comment about this article using the form below. Make sure you provide a valid email address
else you won't be notified when the author replies to your comment
Please note that all comments are moderated and will be deleted if they are

Not relavant to the article


Spam
Advertising campaigns or links to other sites
Abusive content.

Please do not post code, scripts or snippets.

10 of 11 18/01/2016 2:44 PM
Dynamically add and display external Image in RDLC Report from code behind in ASP.Net http://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx

Like 10k Follow @ASPSnippets 1.3k

Name

Email

Comment

Security code:

Add Comment

What our readers say

Katheeja
This site is like Google for asp.net developers. Simple and worthy..
Petros
The simple ones are the best just plug in a few lines of code and it does the job complete as well demo and source available
PeteO
75 other websites... all with same example that did not work then I found yours. Thank you for your hard work.
Iron
You are number one. Thanks.
samruddhi
Really awesome and very helpful site ever.....

Subscribe

Please enter your email address:

Subscribe

© 2016 www.aspsnippets.com All rights reserved | Privacy Policy | Powered by Excelasoft Solutions

11 of 11 18/01/2016 2:44 PM

You might also like