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