Friday, January 4, 2019

Pass Parameter with image in RDLC report Viewer in asp.net

Pass Parameter with image in RDLC Report Viewer in asp.net

In this article SKOTechLearn describe the easy way that how to pass parameter with image in RDLC Report Viewer in ASP.net 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.

What we have to remember for this process?
  • Insert some input TextBox in Form
  • 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 ASP.net
Add web controls
After that Create RDLC Form like "Report1.rdlc".

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
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.
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:
Display
Original Size
Fit to Size
Fit to Proportional
Clip
For Stretch size, we will choose "Fit to Size" option.

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.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 report button. And enjoy the reporting at runtime.
Dynamic pass value in Report Output
Now, try it yourself to design  a report with passing parameter with image in RDLC Report Viewer in ASP.net with easy tech tips by SKOTechLearn.

0 comments: