Solved

VS2005 - ASP.NET - ReportViewer Control - passing parameters to a server report

Posted on 2007-03-20
8
629 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:GRCHELPDESK
8 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 18761211
0
 
LVL 2

Author Comment

by:GRCHELPDESK
ID: 18764588
Hey Emoreau,

Thanks for the feedback.  I've already been to this site, but I'm having trouble finding what I want there.  
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 18765659
have you seen question 10 and "Parameter prompting in local mode" ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:GRCHELPDESK
ID: 18766188
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!
0
 
LVL 2

Author Comment

by:GRCHELPDESK
ID: 18773847
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("LOGON_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.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote

            'Set the Report Viewer - Server URL & Report Path
            ReportViewer1.ServerReport.ReportServerUrl = New Uri("http://YOURSERVER/ReportServer")
            ReportViewer1.ServerReport.ReportPath = "/FOLDER/REPORT_NAME"

            'Setup parameter collection
            Dim pInfo As Microsoft.Reporting.WebForms.ReportParameterInfoCollection
            Dim paramList As New Generic.List(Of Microsoft.Reporting.WebForms.ReportParameter)

            'Insert parameter list - NTID is the parameter name my report is expecting
            paramList.Add(New Microsoft.Reporting.WebForms.ReportParameter("NTID", lblAgentID.Text.ToUpper, False))
            ReportViewer1.ServerReport.SetParameters(paramList)
            pInfo = ReportViewer1.ServerReport.GetParameters()

            'Refresh the report
            ReportViewer1.ServerReport.Refresh()

        End If

There you go, I hope that helps.
GRCHELPDESK
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 19097787
PAQed with points refunded (500)

Computer101
EE Admin
0
 

Expert Comment

by:darelstokes
ID: 26138556
You can also pass these parameters rather easily as follows:

        ReportParameter param1 = new ReportParameter("param1", "value1");
        ReportParameter param2 = new ReportParameter("param2", "value2");
        ReportViewer1.ServerReport.SetParameters(new ReportParameter[] { param1, param2 });

Posted as a clarification to us C# guys :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now