Solved

need to format tablix cell based on data

Posted on 2011-02-15
5
1,298 Views
Last Modified: 2012-05-11
SSRS Newbie here.
Using SQL 2008 R2

I need to examine a report tablix cell and, if it begins with a certain text, say "xyz:" I need to change the background color of that cell and peel off the letters "xyz:".

So if the data was "xyz:Michigan" the report would show the word "Michigan" with a green background.

I know I can go into the textbox proprties fill property and do something like:
=Iif(ReportItems!State like "xyz:", "Green", "No Color")

So, for color changing the cell background, the problem is of course that SSRS doesn't like the "like" operator. What can I use in its place?

I'm not even sure where to begin on removing the "xyz:". Any ideas from our SSRS experts?

As a follow-up, does anyone have a good link to SSRS Expression examples? I've tried the one in MSDN (http://msdn.microsoft.com/en-us/library/ms157328.aspx) and while it has some good examples, none that really help me here.

Thanks in advance.
0
Comment
Question by:kalittaair
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 34903055
Ok here you go...
Place this code in your Report Properties Code Tab.......
Public Function ReplaceData(ByVal str As String, ByVal sData As String) As String
        Return System.Text.RegularExpressions.Regex.Replace(sData, str, "")
End Function

The str is the string you are searching for; and the sData is the whole data field that you are wanting to check.

Place this example code in your Textbox or Cell
=Code.ReplaceData("xyz", "xyz:Michigan")
on the report field more like this
=Code.ReplaceData("xyz",Fields!MyData.Value)
0
 

Author Comment

by:kalittaair
ID: 34916413
Planocz,

Firstly, thank you for your quick posting and I apologize for the delayed response. I've been out of the office.

This works great except when the data returned is NULL. In that case I get an "#Error" in my field. Sometimes the data coming back from the DB will be NULL. In that case it should do nothing, and just display no value. How can I handle that?

Also, any idea on how I can change the background color when the "xyz:" exists?

Thanks again.
0
 
LVL 27

Expert Comment

by:planocz
ID: 34919015
Change to this code

Public Function ReplaceData(ByVal str As String, ByVal sData As String) As String
        If IsNothing(str) then
           Return Nothing
        Else
           Return System.Text.RegularExpressions.Regex.Replace(sData, str, "")
       End If
       Return Nothing
End Function
0
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 34919093
0
 

Author Closing Comment

by:kalittaair
ID: 34921512
All works great. Thanks for all your help!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Steps to solve SSRS SQL 2008 R2 User Access Control (UAC) Permission Error With the introduction of SQL Server 2008 R2 and Vista (Windows 7 as well) came new enhanced security features. One of the features included was User Access Control (UAC) t…
A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question