Parameter from session

2 posts, 0 answers
  1. Arshad
    Arshad avatar
    2 posts
    Member since:
    Nov 2012

    Posted 29 Nov 2012 Link to this post

    hello i added a reportviewer and from its properties set the report and a parameter, but the value for the parameter has to come from session variable, i want to achieve this by adding it in the reports.parameters, how do i set it.

    i do not want to do it from codebehind.

  2. Steve
    Steve avatar
    10941 posts

    Posted 03 Dec 2012 Link to this post

    Hello Arshad,

    If you have set a report source to the ASP.NET ReportViewer, then you have noticed that the report parameters are not serialized in the resulting markup and therefore you cannot set their values declaratively. You can however do this quite easily with some code. As HttpContext is not available within the report expression context directly, you can use it from the calling application e.g.:

    //Create a new instance of the Report1
    Telerik.Reporting.Report report1 = new Report1();
    //Gets the current user name from the CurrentUserName Session variable
    string un = HttpContext.Current.Session["CurrentUserName"].ToString();
    //Set a value to a Report Parameter1 used in a report filter
    report1.ReportParameters["Parameter1"].Value = un;
    //assign the report to a report viewer
    InstanceReportSource irs = new InstanceReportSource();
    irs.ReportDocument = report1;
    ReportViewer1.ReportSource = irs;

    All the best,
    the Telerik team

    HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

Back to Top