C# 如何将参数值从rdlc报告传递到web窗体项目中的方法?
我有一份rdlc报告,它绑定到以下类:C# 如何将参数值从rdlc报告传递到web窗体项目中的方法?,c#,asp.net,webforms,rdlc,localreport,C#,Asp.net,Webforms,Rdlc,Localreport,我有一份rdlc报告,它绑定到以下类: public class Product { DataContext context; public Product() { context = new DataContext(); } public List<Product> GetBoughtItemsForUser(string userName) { //linq query to collect data return query.T
public class Product
{
DataContext context;
public Product()
{
context = new DataContext();
}
public List<Product> GetBoughtItemsForUser(string userName)
{
//linq query to collect data
return query.ToList();
}
public string Name {get;set;}
public int Quantity {get;set;}
}
公共类产品
{
数据上下文;
公共产品()
{
context=newdatacontext();
}
公共列表GetBoughtItemsForUser(字符串用户名)
{
//用于收集数据的linq查询
返回query.ToList();
}
公共字符串名称{get;set;}
公共整数数量{get;set;}
}
在我的rdlc中,我将报表数据集设置为GetBoughtItemsForUser。现在我想传递用户名值,它实际上是Page.User.Identity.Name,那么我应该怎么做呢 试试这个
var p = new Product();
//fill class properties with data
ReportParameter[] params = new ReportParameter[2];
params[0] = new ReportParameter("Name ", p.Name , false);
params[1] = new ReportParameter("Quantity ", p.Quantity , false);
this.ReportViewer1.ServerReport.SetParameters(params);
this.ReportViewer1.ServerReport.Refresh();
rv = ReportViewer1;
rv.LocalReport.ReportPath = @"Report.rdlc";
rv.LocalReport.DataSources.Clear();
ReportDataSource rs = new ReportDataSource("DataSetName", GetData());
rv.LocalReport.DataSources.Add(rs);
ReportParameter param = new ReportParameter("paramName", paramValue);
rv.LocalReport.SetParameters(param);
rv.LocalReport.Refresh();
试试这个
rv = ReportViewer1;
rv.LocalReport.ReportPath = @"Report.rdlc";
rv.LocalReport.DataSources.Clear();
ReportDataSource rs = new ReportDataSource("DataSetName", GetData());
rv.LocalReport.DataSources.Add(rs);
ReportParameter param = new ReportParameter("paramName", paramValue);
rv.LocalReport.SetParameters(param);
rv.LocalReport.Refresh();
这很容易-
如果我假设您使用的是Web应用程序。只需在UI层的某个地方设置一个会话变量,比如:Session[“exp”]=6强>
现在假设您的类产品位于业务层,并且数据集中的RDLC文件正在调用您的函数GetBoughtItemsForUser
按照以下步骤配置RDLC文件-
该in控制器是否可以将参数从MVC5控制器发送到rdlc报告生成器aspxis该in控制器是否可以将参数从MVC5控制器发送到rdlc报告生成器aspx