reporte.aspx
<rsweb:ReportViewer ID="rvMiReporte" runat="server" Width="100%"
Font-Names="Verdana"
Font-Size="8pt"
InteractiveDeviceInfos="(Collection)"
WaitMessageFont-Names="Verdana"
WaitMessageFont-Size="14pt">
</rsweb:ReportViewer>
<asp:Button id="btnListarReporte" runat="server" OnClick="btnListarReporte_Click" text="Reporte"/>
reporte.aspx.cs
protected void btnListarReporte_Click(object sender, EventArgs e)
{
DataTable dt = LlenarDatos();
//el DataSet de nuestro reporte rldc se llama "Cabecera"
ReportDataSource rds = new ReportDataSource("Cabecera", dt);
rvMiReporte.LocalReport.DataSources.Clear();
rvMiReporte.LocalReport.ReportPath = "reportes\\miReporte.rdlc";
rvMiReporte.LocalReport.DataSources.Add(rds);
rvMiReporte.LocalReport.ReportPath = "reportes\\miReporte.rdlc";
rvMiReporte.LocalReport.DataSources.Add(rds);
}
Ahora, si el reporte posee un sub-reporte, con detalles por ejemplo, lo único que hay que agregar es lo siguiente.
El método para cargar el sub-reporte
protected void cargarSubReporte(object sender, SubreportProcessingEventArgs e)
{
DataTable detalles = GetDetalles();
ReportDataSource rdsDetalles = new ReportDataSource("Detalles", detalles);
e.DataSources.Add(rdsDetalles);
}
ReportDataSource rdsDetalles = new ReportDataSource("Detalles", detalles);
e.DataSources.Add(rdsDetalles);
}
protected void btnListarReporte_Click(object sender, EventArgs e)
{
DataTable dt = LlenarDatos();
ReportDataSource rds = new ReportDataSource("Cabecera", dt);
rvMiReporte.LocalReport.DataSources.Clear();
rvMiReporte.LocalReport.ReportPath = "reportes\\miReporte.rdlc";
rvMiReporte.LocalReport.ReportPath = "reportes\\miReporte.rdlc";
rvMiReporte.LocalReport.SubreportProcessing +=
new SubreportProcessingEventHandler(cargarSubReporte);
rvMiReporte.LocalReport.DataSources.Add(rds);
rvMiReporte.LocalReport.DataSources.Add(rds);
}
Y listo. :)