Pass Parameter in RDLC report Viewer & Insert image in Report Viewer in asp.net

In this article SKOTechLearn describe the easy way that how to Pass Parameter in RDLC Report Viewer in ASP.net with easy tech tips. Passing value through database in RDLC Report in ASP.Net is easy to directly connect through properties.  And here you can learn easily to Pass Image in Report Viewer in ASP.Net.

But when we talk about run time pass value in RDLC Report then it is something difficult, because If we want to pass image or any dynamic value from textbox to Report Viewer, we have to learn more things for it. So let’s start about what's new regarding to this process?

How To Create or Design Report Viewer(RDLC) in ASP.Net (Steps With Image)?

What we will have to remember regarding to Report Designing process?

◉ Insert some component or controls in WebForm
◉ Add RDLC Report in ASP.Net Project
◉ Create Parameter in RDLC Report according to Passing value type
◉ Drag all Parameter into RDLC Report form.
◉ Add "ReportViewer" web control on WebForm.
◉ Add "ScripManager" web control.

Now, we will learn it through step by step:

Step1: Create WebForm in ASP.Net and Add Web Controls

First we have to create new webform and add some web controls including “ReportViewer” and “ScriptManager”

Remember one thing “ReportViewer” and “ScriptManager” play important role for Showing Report in ASP.Net.
Add controls in Webform in ASP.net
Add web controls
First we Add Report Viewer form in project, we have to save RDLC Form like "Report1.rdlc".

Design Stylish Button in ASP.Net

Step2: RDLC Report with Parameter Settings

RDLC Report Parameter creation with point to point described bellow.

➤ Open RDLC, Go to “Report Data” window.

➤ Find “Parameter” and right click on it.

➤ Click on “Add Parameter…” option.

➤ This will show “Report Parameter Properties” screen.

➤ Type Parameter name inside “Name” Box and set Data Type as 'Text' from "Data Type:" box. Then press “OK” button.

Create Parameter in RDLC Report
Create Parameter with Settings
As you can see, your created parameter has been added to Parameters Folder.

How to Pass Parameter in Report Viewer in RDLC in ASP.Net?


Step3: Image Parameter Creation Settings

In this step, we will learn how to Pass Image parameter in RDLC Report. For Image Parameter creation, follow the steps.

➤ First create a parameter same as created in above given steps.

➤ Insert “Image” control on RDLC Form.

➤ Right click “Image” report control and find “Image Properties…”.

➤ The selection will show “Image Properties” screen.

➤ Select “External” option from “Select the image source:” combo in “General" Option.

➤ Click on “Function” Parameter Function button in RDLC button from “Use this image:” option.

➤ This button will show “Expression” screen.

➤ Select “Parameters” option from “Category:” list.

➤ Your created name will show in “Values:” list.

➤ Input parameter name which you want to create for passing image in Report.

Inset Image in Report Viewer in ASP.Net.

Image Properties setting on RDLC
Image Properties setting
You can change Image size according to requirement. Choose option “Size” option from “Properties” and this will show the following options.

Image display size setting:
Display
Original Size
Fit to Size
Fit to Proportional
Clip

For Stretch size, we will choose "Fit to Size" option.

Add Menu and Design Menu with Different CSS Style in ASP.Net

Step4: Design RDLC Report

After that Design your RDLC Form. For designing it, drag created parameter name wherever you want to place like bellow. you can drag it one by one. there is no way to drag with all selection.
Drag parameter in RDLC Report
Drag parameter in Report

Step5: RDLC Report Parameter Pass value Code

Suppose we want to show value during button’s press. So, let’s write code inside Button’s click event.

Protected Sub ShwRpt_Btn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ShwRpt_Btn.Click
   ReportViewer1.LocalReport.Refresh()
   ReportViewer1.LocalReport.ReportPath = Server.MapPath("\Report1.rdlc")
   ReportViewer1.LocalReport.EnableExternalImages = True
   Dim paramtr(3) As ReportParameter
   paramtr(0) = New ReportParameter("ParaCustSrno", CustSr_Txt.Text)
   paramtr(1) = New ReportParameter("ParaCustName", C_NM_Txt.Text)
   paramtr(2) = New ReportParameter("ParaCustMono", C_MN_txt.Text)
   paramtr(3) = New ReportParameter("ParaCustImg", "file:///" + "C:\SKOTechLearn.jpg")

   ReportViewer1.LocalReport.SetParameters(paramtr)
   ReportViewer1.LocalReport.Refresh()
End Sub

For “ReportParameter”, you have to import the given following namespace just above the main class of webform.

Imports Microsoft.Reporting.WebForms

When you complete all above process, just run application, and input values inside TextBox and press "Show in Report" button as describe following animated image. And enjoy the reporting at run-time.
Dynamic pass value in Report Output
Now, try it yourself to design  a report with passing Parameter in RDLC Report Viewer  and Insert Image in Report Viewer in ASP.net with easy tech tips by SKOTechLearn.

There is Following other Learning Process:

Glowing TextBox in Different Style in ASP.Net

Layout Design (Header, Footer, SideBar, Content) in ASP.Net

0 comments: