簡體   English   中英

如何將參數值從rdlc報告傳遞到Web表單項目中的方法?

[英]how to pass a parameter value from rdlc report to a method in web forms project?

我有一個rdlc報告,綁定到以下類:

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;}
}

在我的rdlc中,我將報告數據集設置為GetBoughtItemsForUser。 現在我想傳遞userName值,這實際上是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(); 
               reportParameters.Clear();
                reportParameters.Add(new ReportParameter("prmClientRef", find));
                reportParameters.Add(new ReportParameter("prmClientName", string.Format("{0} {1}",                    allval.Title, allval.ClientName)));

                this.viewerInstance.LocalReport.SetParameters(reportParameters);
                this.ProductBindingSource.DataSource = storageToPrint.Where(x => x.ClientRef == find).ToList();
                this.viewerInstance.RefreshReport();
                this.viewerInstance.Refresh();

很容易 -

如果我假設您正在使用Web應用程序。 只需在UI層中的某處設置一個Session變量,即: Session [“exp”] = 6;

現在假設您的類Product在業務層中,並且您的函數GetBoughtItemsForUser正由數據集中的RDLC文件調用。

請按照以下步驟配置RDLC文件 -

  1. ObjectDataSource中選擇ConfigureDataSource ,然后在您的業務層中包含方法 - GetBoughtItemsForUser

  2. 現在,在Define Data Methods窗口中,選擇您的方法 - GetBoughtItemsForUser ,在我的例子中,它是GetAllFaculty。

在此輸入圖像描述

  1. 點擊下一步

在此輸入圖像描述

  1. 現在,您將自動獲取“ 定義參數”窗口(僅在參數化函數的情況下),此處選擇參數源並在您在UI層中使用的SessionField中提供相應的參數名稱,在此情況下,它是Session類型和exp。

  2. 點擊完成按鈕,你就完成了。

注意:您不必擔心將Session變量轉換為適當的類型,在大多數情況下,它將自動完成。 否則,您可以點擊“顯示高級屬性”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM