Is there a way to put subreports in headers in SSRS?
Asked Answered
C

6

10

I would like to use a sub report, since it gets used on many reports, in the header. However, sub reports won't go into the header and neither will field values. Although, parameters will go just fine.

Any suggestions or references for how to bypass this?

Correggio answered 19/10, 2009 at 15:18 Comment(0)
C
4

I approcahed this the other way.

Created a report which just contained a header and a footer.

Then for every report we need we just created a sub report.

I know it isn't anywhere near perfect. But it worked for our reports.

Another option is to create an assembly which pumps data into a field in the header. Works fine if there's nothing too graphical in the header...

Coraciiform answered 19/10, 2009 at 15:32 Comment(1)
I was afraid I'd hear a response like that. The headers are a bit different for each report. With the exception of the piece I wanted the sub report for. Thanks!Correggio
I
4

I've been confronted with the exact same problem. After several hours, I found a solution (without a subreport).

In SSRS 2012 exists the "Rectangle". I never really looked into it because I thought it's just for graphical use. In fact you can group multiple elements in it. The whole rectangle you can publish as Reportpart. This reportpart you can use in other reports, even in the header or footer.

Isabelisabelita answered 2/7, 2012 at 9:28 Comment(1)
This is a better answer to the original question than the one that has a green check.Phip
T
1

Use the Globals!PageName Built-in-field at the Master Page level in the header or footer, then define the PageName value in each subreport. This will allow the header or footer to change with the string value defined in the PageName variable.

For example: set a footer textbox to: [&PageName] or =Globals!PageName

In each subreport called by the Master Page, define the PageName value to:

<PageName>This is the Dynamic Page Footer String.  You can include subreport names, or any dynamic subreport text here </PageName>

I set the PageName value in the subreports, in code view, in the tablix definition directly below the section:

<DataSetName>YourDataSetName</DataSetName> 

For more details on Global variables that you can use look at:
https://msdn.microsoft.com/en-us/library/dd255216.aspx

Timikatiming answered 28/6, 2016 at 17:22 Comment(0)
H
0

One suggestion that may help in a limited subset of cases: you can fill a parameter with a default value from a dataset, and use that parameter in the header. Of course, this only gets you one field/value at a time, but if you only need one or two items from the database into your header this may be a decent workaround.

Homerhomere answered 30/8, 2012 at 5:30 Comment(0)
D
0

SSRS will not allow subreports into the Header. I have had this issue, and I think I have a solution. Add the subreport as an additional dataset, and put the response into a text box. It works for me...?

Dennisedennison answered 11/1, 2017 at 14:28 Comment(1)
Though this was not a direct solution but a workaround idea so really don't think our answer should have been down voted. So up voted.Saleable
T
0

Got the idea from this answer: https://mcmap.net/q/1166527/-rdlc-reports-use-a-sub-report-as-a-report-header

can't really post it there, since the topic is about rdlc, which is only client-side. But I would say it fits here.

Create an image, set its size to fit proportionally, with the following url:

http://*reportserverUser*:*reportserverPassword*@*ssrsHost*/ReportServer?%2f*reportName*&rs:Command=Render&rs:Format=IMAGE&rc:OutputFormat=BMP&rc:dpix=1000&rc:dpiy=1000

&rs:Format=IMAGE give me an Image.

&rc:OutputFormat=BMP as a BMP, since Reports can't handle TIFF's.

&rc:dpix=1000&rc:dpiy=1000 give me a higher resolution, so it wont look ugly

EDIT: Seems to work locally in VisualStudio but not on the ReportServer. Might have to create a custom DLL for the authentication.

EDIT2:

[System.Security.SecuritySafeCritical]
[WebPermission(System.Security.Permissions.SecurityAction.Assert, Unrestricted = true)]
public static string GetReport(string reportname)
{

    // request file permission for config-file
    FileIOPermission f = new FileIOPermission(FileIOPermissionAccess.Read, @"c:\ssrs\ssrsutils_auth.txt");
    f.Assert();

    // BASE-URL\tusername\tpassword
    var config = File.ReadAllText(@"c:\ssrs\ssrsutils_auth.txt");

    // Get BASE-URL and insert reportname into {0} placeholder
    var str = string.Format(config.Split('\t')[0], reportname);
    var requestUri = new Uri(str);

    // Set Credentials according to configuration
    NetworkCredential nc = new NetworkCredential(config.Split('\t')[1], config.Split('\t')[2]);

    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUri);

    request.Credentials = nc;

    // Give me an Image object
    var img = Image.FromStream(request.GetResponse().GetResponseStream());

    // and return as Base64
    return GetBase64(img);
}

private static string GetBase64(Image image)
{
    using (MemoryStream m = new MemoryStream())
    {
        image.Save(m, ImageFormat.Png);
        byte[] imageBytes = m.ToArray();
        return Convert.ToBase64String(imageBytes);
    }
}

Then you set the image-source to database, use the following expression:

=*Project*.*Class*.GetReport("*ReportName*")

Mime Type to image/bmp and you are good to go

Example-Config c:\ssrs\ssrsutils_auth.txt (replace [TAB] with actual \t - ASCII 09):

http://*ssrsHost*/ReportServer?%2f{0}&rs:Command=Render&rs:Format=IMAGE&rc:OutputFormat=BMP&rc:dpix=1000&rc:dpiy=1000[TAB]username[TAB]password

By the way, be aware of the way, SSRS handles CAS. https://mcmap.net/q/1166528/-ssrs-custom-assembly-permissions-issue

Tumid answered 4/8, 2021 at 13:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.