Friday, January 4, 2019

Pass Parameter in RDLC report Viewer & Insert image in Report Viewer in

Pass Parameter in RDLC report Viewer & Insert image in Report Viewer in

In this article SKOTechLearn describe the easy way that how to Pass Parameter in RDLC Report Viewer in with easy tech tips. Passing value through database is very easy to learn and process. But when we talk about run time pass value in report then it is something difficult. Because we have to learn more things for it. So let’s learn about it.

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

What we have to remember for Report process?
  • Insert some input TextBox in WebForm
  • Add RDLC into your Project
  • Create Parameter in RDLC according to Passing value type
  • Drag all Parameter into RDLC form.
  • Add "ReportViewer" web control on WebForm.
  • Add "ScripManager" web control.
Now, we will learn it through step by step:

Step1: Create WebForm and Add Web Controls
First create new webform and add some web controls including “ReportViewer” and “ScriptManager” like following:
Add controls in Webform in
Add web controls
After that Create RDLC Form like "Report1.rdlc".

Design Stylish Button in ASP.Net

Step2: RDLC Report with Parameter settings
Open RDLC and create Parameter as describe following.
  • Open RDLC, Go to “Report Data” window.
  • Find “Parameter” and right click on it.
  • Click on “Add Parameter…”
  • “Report Parameter Properties” screen will appear
  • Type “Name” and set Data Type as “Text”. Then press “OK” button.
Create Parameter in RDLC Report
Create Parameter with Settings

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

Step3: Image Parameter Creation Settings
For Image Para creation, follow the steps.
  • First create a parameter same as other created
  • Insert “Image” control on RDLC Form.
  • Right click “Image” report control and find “Image Properties…”
  • “Image Properties” screen will appear.
  • 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.
  • “Expression” screen will appear.
  • Select “Parameters” option from “Category:” list.
  • Your created name will show in “Values:” list.
  • Select name which you create for image.

Inset Image in Report Viewer in ASP.Net.

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

Image display size setting:
Original Size
Fit to Size
Fit to Proportional
For Stretch size, we will choose "Fit to Size" option.

Add Menu and Design Menu in ASP.Net

Step4: Design RDLC Report
After that Design your RDLC Form. For designing it, drag created para 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
Step6: 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.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")

    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 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