How to print an RDLC report in ASP.NET

0
I have rdlc created, and I have a page aspx that has a print button, when I click print I want to call the rdlc that I have created for printing. How do I?

    
asked by anonymous 04.05.2015 / 18:47

1 answer

0

The Print button should call another aspx. In this aspx, you can do as follows:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        ReportViewer1.ProcessingMode = ProcessingMode.Local;
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
        var dsClientes = GetData("select top 20 * from clientes");
        ReportDataSource datasource = new ReportDataSource("Clientes", dsClientes.Tables[0]);
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(datasource);
    }
}

private Customers GetData(string query)
{
    string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    SqlCommand cmd = new SqlCommand(query);
    using (SqlConnection con = new SqlConnection(conString))
    {
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            cmd.Connection = con;

            sda.SelectCommand = cmd;
            using (Customers dsClientes = new Customers())
            {
                sda.Fill(dsClientes, "DataTable1");
                return dsClientes;
            }
        }
    }
}

I will take the example here .

    
04.05.2015 / 19:13