通过asp.net代码填写rdlc报告

时间:2014-04-21 17:03:42

标签: asp.net c#-4.0 report c#-3.0 rdlc

我正在尝试使用Typed数据集填充RDLC报告。我试图通过代码填写它,但不知道在特定的地方放什么。

数据集名称为GPSDBDataSet.XSD,报告名称为Report.rdlc,数据表名称为坐标。

使用Microsoft.Reporting.WebForms;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ReportViewer1.Visible = true;

            ReportDataSource rds = new ReportDataSource();

            ReportViewer1.Reset();

            ReportViewer1.ProcessingMode = ProcessingMode.Local;

            LocalReport rep = ReportViewer1.LocalReport;                      

            rep.Refresh();

            rep.ReportPath = "Report.rdlc";


            rds.Name = ???????;


            rds.Value = ????;

            rep.DataSources.Add(rds);
    }
}

1 个答案:

答案 0 :(得分:1)

已经有一段时间了,但试试这个。

rds.name =“yourdatasetname”//在你的情况下,这个直到coodinates

rds.value = ds.table [0];

代码 DataSet ds = new DataSet();

try
{
    ds = RetrieveData();//some func that returns dataset...
    ReportDataSource reportDataSource = new ReportDataSource();
    // Must match the DataSource in the RDLC
    reportDataSource.Name = "DataSet1";//coordinates in your case.
    reportDataSource.Value = ds.Tables[0];
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(reportDataSource);
    ReportViewer1.LocalReport.Refresh();

}
catch (Exception Ex)
{
    throw new Exception("Error Generating the Report", Ex);
}