DON LAZE
DON LAZE

Reputation: 25

how to pass report parameter in reportviewer control

I want to display "ReportView" with parameter's "textbox and button" Ex. Like a search button . Can you give me some code example.

Thank's in advance.

Upvotes: 2

Views: 9202

Answers (2)

Emz
Emz

Reputation: 527

hope you are using asp.net WebForms,

  1. Open the report you want to add the parameter to.
  2. In the Report Data pane(CTRL+ALT+D) there's parameters folder. Right click on it to add a new parameter, From the Report Parameter Properties dialog specify the parameter name i.e ReportParam1 and click OK to add.
  3. Drag the new parameter on to the report
  4. The code(C#) below gets a value from the textbox and displays it on the report.

    reportViewer1.LocalReport.ReportEmbeddedResource = "path_to_the_embedded_report";
        ReportParameter[] parameters = new ReportParameter[1];
        parameters[0] = new ReportParameter("ReportParam1", textbox1.Text, true);
        reportViewer1.LocalReport.SetParameters(parameters);
        reportViewer1.RefreshReport();

    You might need to resolve some references and add report viewer to your project via NuGet.

Hope that helps.

Upvotes: 2

Mikhail  Gerasimov
Mikhail Gerasimov

Reputation: 67

I can not comment your question, sorry. If you use server Report Microsoft you can use, for your RDL file. Can you add information about ReportProgramm wich you use?

    string[] parameter = = new string[3] {"1","2","3" };//here you can change to your TextBox
                            //This is optional if you have parameter then you can add parameters as much as you want
Microsoft.Reporting.WebForms.ReportParameter[] param = new Microsoft.Reporting.WebForms.ReportParameter[3];
    param[0] = new Microsoft.Reporting.WebForms.ReportParameter("firstParam", parameter[0], true);
    param[1] = new Microsoft.Reporting.WebForms.ReportParameter("SecondParam", parameter[1], true);
    param[2] = new Microsoft.Reporting.WebForms.ReportParameter("thirdParam", parameter[2], true);
    Microsoft.Reporting.WebForms.ReportViewer report = new Microsoft.Reporting.WebForms.ReportViewer();
    report.ServerReport.ReportServerCredentials = new CustomReportCredentials("Name", "Password", "DomName");
                            report.ServerReport.ReportServerUrl = new Uri("yourPathtoserver");// Report Server URL
    report.ServerReport.ReportPath = "reportpathWithHimName";// Report Name with path!
    report.ServerReport.SetParameters(param);
    report.ServerReport.Refresh();

Sorry, if I not answered your question.

public class CustomReportCredentials : IReportServerCredentials
    {
        private string _UserName;
        private string _PassWord;
        private string _DomainName;

        public CustomReportCredentials(string UserName, string PassWord, string DomainName)
        {
            _UserName = UserName;
            _PassWord = PassWord;
            _DomainName = DomainName;
        }

        public System.Security.Principal.WindowsIdentity ImpersonationUser
        {
            get { return null; }
        }

        public ICredentials NetworkCredentials
        {
            get { return new NetworkCredential(_UserName, _PassWord, _DomainName); }
        }

        public bool GetFormsCredentials(out Cookie authCookie, out string user,
         out string password, out string authority)
        {
            authCookie = null;
            user = password = authority = null;
            return false;
        }
    }

Upvotes: 0

Related Questions