This is a migrated thread and some comments may be shown as answers.

Parameter from session

1 Answer 401 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Arshad
Top achievements
Rank 1
Arshad asked on 29 Nov 2012, 01:54 PM
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.

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 03 Dec 2012, 04:43 PM
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,
Steve
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!

Tags
General Discussions
Asked by
Arshad
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or