Good day! I want to know how to pass a value to reportviewer textbox. I want to pass the value of a datetimepicker to reportviewer textbox. How can I do this? Both reportviewer and datetimepicker are in the same form. any help is much appreciated. Thank you.

Recommended Answers

All 3 Replies

Can you please be more specific? What is a "reportviewer textbox"? Perhaps a little of your code would also help.

It's really pretty simple.

Steps:

  1. Goto your Report in design view and hit the F4 key to bring up the property window for the report.

  2. You need to define a ReportParameter. Click on the elipsis next to the ReportParameters field in the property windows. This will bring up the "Report Parameters" dialog box. Click "Add" then "OK". This will add a string parameter with name "Report_Parameter_0". You can change the name later.

  3. Now click on your textbox and hit the "F4" key again if needed to view its properties. We are interested in the "Value" property. Enter this for the value. You could also use the expresion builder dialog.

    =Parameters!Report_Parameter_0.Value

Now your textbox is setup to set the value from code.

  1. Now for the code to set the parameter. Make sure that you project has a Reference to "Microsoft.Reporting.WinForms"; it should since you already have added the reportviewer control.

I am assuming that your reportviewer is named "ReportViewer1" and the DateTimePicker is named "DateTimePicker1".

      'Define an array to hold the parameter definintion.  
      'This could also be a List(of Microsoft.Reporting.WinForms.ReportParameter)
      'or any class that implements IEnumerable
      'Since I am assuming you have only 1 report parameter, the array will have size=1
      'If you have other parameters, size the array appropriately and define a value for
      'all parameters.  Afterwards, You can set an individual parameter of a multi-parameter report
      Dim params(0) As Microsoft.Reporting.WinForms.ReportParameter

      'The value can only be set in the ReportParameter constructor
      params(0) = New Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_0", _
                                                                   DateTimePicker1.Value.ToShortDateString)

      'LocalReport is the current Report assigned to the viewer. Make sure it is set.
      'Load RDLC from embedded file.  You probably have done this in the form designer

         'ReportViewer1.Reset() 'If Viewer had previous Report, Reset it before loading new report
         'ReportViewer1.LocalReport.ReportEmbeddedResource = "WindowsApplication1.Report3.rdlc"

      'Set the Reports parameters
      ReportViewer1.LocalReport.SetParameters(params)

      'Refresh the report to reflect the changes
      Me.ReportViewer1.RefreshReport()

C# - Query based on Windows application

I need to pass the values from previous form to Report Viewer ---> Subreport Parameters in C# using Microsoft Report Viewer

i need the solution to implement this concept

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.