GRCHELPDESK
asked on
VS2005 - ASP.NET - ReportViewer Control - passing parameters to a server report
Hello Experts,
I'm trying to use the ReportViewer control to display a SQL Server 2005 Reporting Services report in my web page. I've been able to get it to display a server report in one of my pages. But what I need now it to be able to pass the report a parameter.
Basically we want to display stats for whoever visits the page. So on page load I pull their Network ID. I then want to pass that report their network ID, and have it show only thier stats.
I'm very new to all of this and I have a deadline fast approaching so any help would be appreciated. Also, if there's a better control or an easier way of doing this I'm open to it. (as long as I'm able to implement it with my limited abilities)
Thanks!
GRCHELPDESK
I'm trying to use the ReportViewer control to display a SQL Server 2005 Reporting Services report in my web page. I've been able to get it to display a server report in one of my pages. But what I need now it to be able to pass the report a parameter.
Basically we want to display stats for whoever visits the page. So on page load I pull their Network ID. I then want to pass that report their network ID, and have it show only thier stats.
I'm very new to all of this and I have a deadline fast approaching so any help would be appreciated. Also, if there's a better control or an easier way of doing this I'm open to it. (as long as I'm able to implement it with my limited abilities)
Thanks!
GRCHELPDESK
see http://www.gotreportviewer.com/
ASKER
Hey Emoreau,
Thanks for the feedback. I've already been to this site, but I'm having trouble finding what I want there.
Thanks for the feedback. I've already been to this site, but I'm having trouble finding what I want there.
have you seen question 10 and "Parameter prompting in local mode" ?
ASKER
Hey Emoreau,
Yes, I've seen that. What I need is to pass a parameter to a report in server mode, not local mode. Thanks!
Yes, I've seen that. What I need is to pass a parameter to a report in server mode, not local mode. Thanks!
ASKER
Ok, I've figured out how to do this. I'm going to post the code for anyone else running into this. This'll show you how to run a server report based on the user logged into the page.
1) Start a new ASP.NET page (VB)
2) Drop a hidden label on the screen to store the user id (call it lblAgentID)
3) Drop the ReportViewer control on the page
4) Paste the following code into your "page Load" event
5) Tweak the Server, Report path, and parameters to fit your scenario
6) Run the page
'Paste me into Page Load event
If Not IsPostBack Then
'capture Logon_User
Dim strLogonUser As String
strLogonUser = Request.ServerVariables("L OGON_USER" )
'remove the domain from strLogonUser to leave the Agent ID
If strLogonUser.IndexOf("\") > 0 Then
'Separate the domain and user id
Dim arrDomain = strLogonUser.Split("\")
lblAgentID.Text = arrDomain(1)
End If
'Set the report Processing Mode
ReportViewer1.ProcessingMo de = Microsoft.Reporting.WebFor ms.Process ingMode.Re mote
'Set the Report Viewer - Server URL & Report Path
ReportViewer1.ServerReport .ReportSer verUrl = New Uri("http://YOURSERVER/ReportServer")
ReportViewer1.ServerReport .ReportPat h = "/FOLDER/REPORT_NAME"
'Setup parameter collection
Dim pInfo As Microsoft.Reporting.WebFor ms.ReportP arameterIn foCollecti on
Dim paramList As New Generic.List(Of Microsoft.Reporting.WebFor ms.ReportP arameter)
'Insert parameter list - NTID is the parameter name my report is expecting
paramList.Add(New Microsoft.Reporting.WebFor ms.ReportP arameter(" NTID", lblAgentID.Text.ToUpper, False))
ReportViewer1.ServerReport .SetParame ters(param List)
pInfo = ReportViewer1.ServerReport .GetParame ters()
'Refresh the report
ReportViewer1.ServerReport .Refresh()
End If
There you go, I hope that helps.
GRCHELPDESK
1) Start a new ASP.NET page (VB)
2) Drop a hidden label on the screen to store the user id (call it lblAgentID)
3) Drop the ReportViewer control on the page
4) Paste the following code into your "page Load" event
5) Tweak the Server, Report path, and parameters to fit your scenario
6) Run the page
'Paste me into Page Load event
If Not IsPostBack Then
'capture Logon_User
Dim strLogonUser As String
strLogonUser = Request.ServerVariables("L
'remove the domain from strLogonUser to leave the Agent ID
If strLogonUser.IndexOf("\") > 0 Then
'Separate the domain and user id
Dim arrDomain = strLogonUser.Split("\")
lblAgentID.Text = arrDomain(1)
End If
'Set the report Processing Mode
ReportViewer1.ProcessingMo
'Set the Report Viewer - Server URL & Report Path
ReportViewer1.ServerReport
ReportViewer1.ServerReport
'Setup parameter collection
Dim pInfo As Microsoft.Reporting.WebFor
Dim paramList As New Generic.List(Of Microsoft.Reporting.WebFor
'Insert parameter list - NTID is the parameter name my report is expecting
paramList.Add(New Microsoft.Reporting.WebFor
ReportViewer1.ServerReport
pInfo = ReportViewer1.ServerReport
'Refresh the report
ReportViewer1.ServerReport
End If
There you go, I hope that helps.
GRCHELPDESK
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also pass these parameters rather easily as follows:
ReportParameter param1 = new ReportParameter("param1", "value1");
ReportParameter param2 = new ReportParameter("param2", "value2");
ReportViewer1.ServerReport .SetParame ters(new ReportParameter[] { param1, param2 });
Posted as a clarification to us C# guys :)
ReportParameter param1 = new ReportParameter("param1", "value1");
ReportParameter param2 = new ReportParameter("param2", "value2");
ReportViewer1.ServerReport
Posted as a clarification to us C# guys :)