SSRS: Change Font and Background Color at Runtime.
Sometimes Clients requirements are very unexceptional but we
need to fulfill them. So the requirement is that Client could change the Font
properties as per their will like they can change “Font Family, Font Size, Font
Style and Background Color of Tablix Header” at any time.
So if N numbers of reports are deployed then “How do you do
it”? Solution is given below:
Create a table in Database like Font_Table or whatever
the name you want to give. Add columns like: Font_Family, Font_Size,
Back_Color etc. Insert only one row in table, if you need more values then add
columns but insert only single row as below:
CREATE TABLE
FONT_TABLE
(
Font_Family VARCHAR(50),
Font_Size VARCHAR(10),
Back_Color VARCHAR(10)
)
INSERT INTO
FONT_TABLE VALUES
('Calibri', 10pt, 'GREEN')
SELECT * FROM FONT_TABLE
NOW, we
can use this table values in our SSRS report’s properties. We can write
expression of Font Properties and many others as well.
Add new
dataset in report. Add query “Select * from Font_Table”
Go to
table header -> Properties -> BackgroundColor -> Expressions ->
Choose color field as below:
For Font
Family:
Do it
same for Font Size, Font Weight etc.
See the
output:
NOW if I
change the values in my Font_Table in database and just refresh the report, you
will see the difference:
UPDATE FONT_TABLE
SET Font_Family =
'Verdana',
Font_Size =
'12pt',
Back_Color = 'Orange'
So you
can change any property at runtime which having expression functionality and
also we can use RGB Code for Color property instead of writing color name. If
you use this property at the time of developing reports then all reports will be
effected. Enjoy and let me know for any question. Thanks.
No comments:
Post a Comment