Pass a parameter to the Report Viewer

0

Hello friends, I have a parameter of a C # method that I want to be shown in a rdlc report

public static void getPerfil(){

   String perfil = "ESTE ES MI PERFIL";
}

I want to add it where it is in the Parameter folder to put it in my report

    
asked by Alex 19.12.2018 в 18:54
source

2 answers

2

Add parameters to the folder is simple, you just need to right click and then click on add, I think your question is more focused on how to send the parameters to the report. To do this you first need to instantiate an array of the ReportParameter class as I show you below:

        ReportParameter[] reportParameters = new ReportParameter[1];
        reportParameters[0] = new ReportParameter("NombreParametro", "VALOR DE TU PARAMETRO", false);

Then if you have your report in a ReportViewer you must access the LocalReport property and then add the parameters:

        reportViewer1.LocalReport.SetParameters(reportParameters);
        reportViewer1.RefreshReport();

In case you do not have a ReportViewer, access the property of your report directly:

        TuReporte..SetParameters(reportParameters);

I hope it will be useful for you.

    
answered by 19.12.2018 / 19:03
source
0

Here is when I generate the report goes to this controller to generate the pdf report

        public static async Task<Byte[]> GetFileComunicado(String Supervisor, String Paciente, long CodigoAtencionMedica, String Location, long CodigoUsuarioSistema)
        {
            ReportDataSource Encabezado = new ReportDataSource
            {
                Name = "Encabezado",
                Value = ExamenDAL.SupervisorToDatatable(Supervisor, "Nombre")
            };

            ReportDataSource Restriccion = new ReportDataSource
            {
                Name = "Restriccion",
                Value = await GetRestriccionByAtencion(Paciente, CodigoAtencionMedica)
            };

            ReportDataSource From = new ReportDataSource
            {
                Name = "From",
                Value = await ExamenDAL.GetMedicoByUsuarioSistema(CodigoUsuarioSistema)
            };

            ReportViewer reportViewer = new ReportViewer
            {
                ProcessingMode = ProcessingMode.Local
            };
            reportViewer.LocalReport.DataSources.Add(Encabezado);
            reportViewer.LocalReport.DataSources.Add(Restriccion);
            reportViewer.LocalReport.DataSources.Add(From);
            reportViewer.LocalReport.DisplayName = "COM-RESTRICCION-MEDICO";
            reportViewer.LocalReport.EnableExternalImages = true;
            reportViewer.LocalReport.ReportPath = System.Web.Hosting.HostingEnvironment.MapPath(Location) + @"Reports\ReportePerfil.rdlc";
            return reportViewer.LocalReport.Render("PDF");
    
answered by 19.12.2018 в 22:14