1

I have a report that contains a drop down of users. I want the currently logged in user to be selected as a default.

The drop down has a value of UserId and UserName. I have attempted the following but no luck:

ReportViewer.ServerReport.SetParameters(new ReportParameter("SelectedUserId", CurrentUser.Id.ToString()));

I can do this with JavaScript as a last resort, but is there a way to do this server side?

Thanks

Update:

UserId is the primary key of the user table and is not derivable from the logged in user name.. is this what you are suggesting?

Didn't realise I could put a query in there though. I do have CurrentUserId as an internal parameter that I am using as a parameter of my SP that populates the drop down.

I use this to set the default to: =Parameters!CurrentUserId.Value

which does work in Visual Studio and the report manager with a default CurrentUserId. However in the report the CurrentUserId is set with:

ReportViewer.ServerReport.SetParameters(new ReportParameter("CurrentUserId", CurrentUser.Id.ToString()));

which appears to be setting it too late for it to be set in the drop down.

Crippledsmurf
  • 3,982
  • 1
  • 31
  • 50
Alistair
  • 1,939
  • 2
  • 22
  • 31

2 Answers2

1

Open the Report Parameters edit form and set the non-queried value for the Default values section of the user id parameter to:

=User!UserID

Note that this is a case-sensitive comparison: if your UserId list is in capitals and your network login is in lower case the lookup of the parameter value will fail.

Also, your network login may have a domain in it that doesn't appear in your userid list - if so, you'll have to strip that out.

For example, let's say your network login is in lower case and has a domain, and the user id list is in upper case with no domain. For the non-queried default parameter value you would use an expression like:

=Ucase(Replace(User!UserID, "MYDOMAIN\", ""))
Chris Latta
  • 20,316
  • 4
  • 62
  • 70
0

Got it working:

Steps:

Add CurrentUserId as a parameter.

For the user drop down, set the default to:

=Parameters!CurrentUserId.Value

Then in the container page:

ReportViewer.ServerReport.SetParameters(new ReportParameter("CurrentUserId", CurrentUser.Id.ToString()));

This wasn't working when running in a container previously.. but it is now..

Alistair
  • 1,939
  • 2
  • 22
  • 31