How To Add Data Result into Header on Report RDLC
1. Prepare fields and data needed for RDLC in Section Report.
2. Go To Layout and Open Report Properties
3. Insert These Code on last line for generating function to be called in header :
Shared offset as IntegerShared newPage as ObjectShared currentgroup1 as ObjectShared currentgroup2 as ObjectShared currentgroup3 as ObjectPublic Function GetGroupPageNumber(NewPage as Boolean, pagenumber as Integer) as Object If NewPage offset = pagenumber - 1 End If Return pagenumber - offsetEnd FunctionPublic Function IsNewPage(group1 as Object, group2 as Object, group3 as Object) As BooleannewPage = FALSEIf Not (group1 = currentgroup1) newPage = TRUE currentgroup1 = group1 currentgroup2 = group2 currentgroup3 = group3 ELSE If Not (group2 = currentgroup2) newPage = TRUE currentgroup2 = group2 currentgroup3 = group3 ELSE If Not (group3 = currentgroup3) newPage = TRUE currentgroup3 = group3 End If End If End IfReturn newPageEnd FunctionShared Data1 as ObjectShared Data2 as ObjectShared Data3 as ObjectShared Data4 as ObjectPublic Function GetData(Num as Integer, Group as integer) as Objectif Group = 1 then Return Cstr(Choose(Num, Split(Cstr(Data1),Chr(177))))End Ifif Group = 2 then Return Cstr(Choose(Num, Split(Cstr(Data2),Chr(177))))End Ifif Group = 3 then Return Cstr(Choose(Num, Split(Cstr(Data3),Chr(177))))End Ifif Group = 4 then Return Cstr(Choose(Num, Split(Cstr(Data4),Chr(177))))End IfEnd FunctionPublic Function SetData(NewData as Object,Group as integer) If Group = 1 and NewData <> "" Then Data1 = NewData End If If Group = 2 and NewData <> "" Then Data2 = NewData End If If Group = 3 and NewData <> "" Then Data3 = NewData End If If Group = 4 and NewData <> "" Then Data4 = NewData End IfEnd Function
4. Close report properties and create table inside body report, open properties of new table and change DataSetName to DataSet_Result
Properties :
5. Select first row and column and open properties of the cell, change the Name and expression :
6. Code for expression : (example)
=Fields!EncodeBarcode128__Search_Description__.Value + Chr(177) + Fields!Item__No__.Value
7. Close the cell property and create 2 text box in header of report, first textbox will declare function group to be called in other text box.
Open properties for the first text box and change value : (example)
=code.SetData(ReportItems!databody.Value,1)
databody is the name of the cell which we has made.
8. Open Second textbox and change the value into :
=Code.GetData(1,1)
Value for GetData depends on how many source table and group we need to display on header
Thats it Finish and save your RDLC