C# 如何在reportviewer控件中传递报表参数

C# 如何在reportviewer控件中传递报表参数,c#,asp.net,C#,Asp.net,我想显示带有参数“文本框和按钮”的“ReportView”,比如搜索按钮。你能给我一些代码示例吗 提前谢谢。对不起,我不能评论你的问题。如果您使用Microsoft server Report,则可以将用于RDL文件。您可以添加有关您使用的ReportProgramm的信息吗 string[] parameter = = new string[3] {"1","2","3" };//here you can change to your TextBox

我想显示带有参数“文本框和按钮”的“ReportView”,比如搜索按钮。你能给我一些代码示例吗


提前谢谢。

对不起,我不能评论你的问题。如果您使用Microsoft server Report,则可以将用于RDL文件。您可以添加有关您使用的ReportProgramm的信息吗

    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();
对不起,如果我没有回答你的问题

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

希望您使用的是asp.net WebForms

  • 打开要向其中添加参数的报告
  • 在报告数据窗格(CTRL+ALT+D)中有一个参数文件夹。赖特 单击它,从报告参数添加一个新参数 “属性”对话框指定参数名称,即ReportParam1和 单击“确定”添加
  • 将新参数拖到报告上
  • 下面的代码(C#)从文本框中获取一个值,并将其显示在 报告

    reportViewer1.LocalReport.ReportEmbeddedResource=“指向嵌入报告的路径”;
    ReportParameter[]参数=新的ReportParameter[1];
    参数[0]=新的ReportParameter(“ReportParam1”,textbox1.Text,true);
    reportViewer1.LocalReport.SetParameters(参数);
    reportViewer1.RefreshReport()

    您可能需要解析一些引用,并通过NuGet将报表查看器添加到项目中


  • 希望这能有所帮助。

    请展示您现在做了什么/尝试了什么。也读
    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();