How to print a RDLC report on Asp.net

Asked

Viewed 548 times

0

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

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 took the example from here.

  • I saw this example, but here you will not find any reportview when typing

  • You added the component ReportViewer1 in aspx as an example?

  • this reportview refers to q? class?

  • Component ReportViewer, section Reporting of the component bar on the left. You have this part in the example.

  • I just typed <rsweb:Reportviewer ID="Reportviewer1" runat="server" Width="600">

  • 1

    It worked here, I’ll test it

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.