我正在尝试使用来自.aspx页面的两个下拉列表中的输入传递两个参数。在rdlc报告中但在其后面的代码中显示错误。
这是我的代码,位于in.aspx.cs
之下using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.Reporting.WebForms;
using System.Web.UI.WebControls;
public partial class RDLC : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
fillcontrols();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
ReportViewer1.Reset();
ReportDataSource rptsrc = new ReportDataSource("DataSet1", GetData());
ReportParameter rp1 = new ReportParameter("Month", ddlMonth.SelectedValue.ToString());
ReportParameter rp2 = new ReportParameter("Year", ddlYear.SelectedValue.ToString());
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp1, rp2 });
ReportViewer1.LocalReport.DataSources.Add(rptsrc);
ReportViewer1.LocalReport.ReportPath = "Report.rdlc";
ReportViewer1.LocalReport.Refresh();
}
catch(Exception ex)
{ }
}
public void fillcontrols()
{
ddlMonth.Items.Clear();
ddlMonth.AppendDataBoundItems = true;
ddlMonth.Items.Add(new ListItem("Select Month", "-1"));
int nMonth = DateTime.Now.Month;
for (int j = nMonth; j <= nMonth + 10; j++)
{
ddlMonth.Items.Add(new ListItem(j.ToString(),j.ToString()));
}
ddlMonth.SelectedValue = "-1";
ddlYear.Items.Clear();
ddlYear.AppendDataBoundItems = true;
ddlYear.Items.Add(new ListItem("Select Year", "-1"));
int nYear = DateTime.Now.Year;
for (int i = nYear-3; i <= nYear + 3; i++)
{
ddlYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
ddlYear.SelectedValue = "-1";
}
private DataTable GetData()
{
DataTable dt = new DataTable();
string conString = System.Configuration.ConfigurationManager.ConnectionStrings["ProjectManagementConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
SqlCommand cmd = new SqlCommand("Select * from ProjectBilling",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
return dt;
}
}
答案 0 :(得分:2)
试试这个。指定报告路径,然后添加数据源。
try
{
ReportViewer1.Reset();
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.DataSources.Clear();
ReportDataSource rptsrc = new ReportDataSource("DataSet1", GetData());
ReportParameter rp1 = new ReportParameter("Month", ddlMonth.SelectedValue.ToString());
ReportParameter rp2 = new ReportParameter("Year", ddlYear.SelectedValue.ToString());
ReportViewer1.LocalReport.ReportPath = "Report.rdlc";
ReportViewer1.LocalReport.DataSources.Add(rptsrc);
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp1, rp2 }) ;
ReportViewer1.LocalReport.Refresh();
}
catch(Exception ex)
{ }