Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Tips on SSRS

0.00/5 (No votes)
6 May 2010 1  
Below are some tips in SSRS:1.      ToDisplay Top N rows in report using Tablix controlCreate a parameter with IntegerDataType and select Default

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Below are some tips in SSRS:

1.      ToDisplay Top N rows in report using Tablix control
Create a parameter with IntegerDataType and select Default values from Properties, under specific values addexpression number of rows you want to display (i.e cint(10)). Now right clickon Tablix control and select properties, select Filters and add new filter
Expression=FieldName
Operator=Top N
Value= =Parameters!TopN.Value as expression.
Now in Report it will display Top N rows.

2.      To GetTotal Pages and Page Number for each Page in Report Footer
Add Textbox and assign the below expression to display total pages and pagenumber in Footer of report
="Page "+ Globals!PageNumber.ToString() +" of"+Globals!TotalPages.ToString()

3.       Viewing SSRS reports using ReportViewer
Add below sample code to view report whichdeployed in server:

ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://computername:8080");
ReportViewer1.ServerReport.ReportPath = @"/Examples/Sample";
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportServerCredentials _ReportCredentials = new ReportServerCredentials("windowsuserid","password");
ReportViewer1.ServerReport.ReportServerCredentials = _ReportCredentials;
ReportViewer1.ServerReport.Refresh();
ReportViewer1.AsyncRendering = false;
ReportViewer1.SizeToReportContent = true;

4.      Adding Fontstyles in Run Time to Tablix controls or Textboxes in SSRS Reports
Select Report from menu and select code from the menu add following code toadd font styles to controls in run time. I have report and want to add fontstyles of Report Heading in run time
Public Function GetColor(ByVal Section as String) as String
IF Section ="Report Heading" Then
                                Return "SteelBlue"
        End IF
End Function
Public Function GetSize(ByVal Section as string) as String
                IF Section = "ReportHeading" Then
                                Return "20pt"
                End IF
End Function
Public Function GetFont(ByVal Section as string) as String            
                Return "Arial"    
End Function
In Report Header I have added Textbox to display the Report heading and addstyles in Run time.
Now right click on Textbox and select properties, under Font add following expressionto add styles in run time. 
In Font ==Code.GetFont(“ReportHeading”) as expression
Size==Code.GetSize(“ReportHeading”) as expression
Color== Code.GetColor(“ReportHeading”) as expression

5.      To  Hide/Show  Textboxes,Tablix controls in Runtime
If there is no data to display in Tablix, then I don’t want to displayTablix control in report.
Right click on Tablix control and select Visibility and add below expressionunder show or hide based on an expression.
=iif(RowNumber(Nothing)> 0,False,True).
This will hide tablix if data is not present, otherwise itwill display the table with data.

6.      To addalternative row colors in Tablix control
Right click on details group of Tablix control, under backgroundColor addbelow expression
=iif(RowNumber("DataSet") mod2 = 0,"Steelblue",”White”)

7.      FormattingDateTime in Report parameters
=Format(Parameter!Parameter1.value,"MM/dd/yyyy")
=Format(Parameter!Parameter1.value,"dd/MM/yyyy")
=Format(Parameter!Parameter1.value,"yyyy-MM-dd")
=Today()              //CurrentDate

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here