Search code examples
c#asp.netwebformsrdlclocalreport

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


i have a rdlc report that is bound to following class:

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

in my rdlc i've set the report dataset to GetBoughtItemsForUser. now i want to pass the userName value which is actually the Page.User.Identity.Name so how should i do this?


Solution

  • 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();