问题
I have an SQL Server 2005 Express Reporting Server and I'm trying update a report to show a coloured label based on a value stored in the database.
I currently store the colour as an aRGB value, but I can change this if required.
I've seen posts on how to use expression in the color property, but I can't embed c# there.
Thanks!
回答1:
SSRS uses VB.NET, not C#, and most places will accept code, it is prefixed with a '=' to let the parser know that it is code. I don't know exactly where you are trying to set the label (in a table, in a floating textbox, etc), but it is very likely that it is doable.
回答2:
After some digging I found out that u have to use VB code.
Here's the steps.
- Add a reference to System.Drawing in the report properties -> reference tab
Add this custom code to the report properties -> code tab
Public Function GetMyColour(myColour as integer) as string Dim colorObj As System.Drawing.Color = System.Drawing.Color.FromArgb(myColour)
return String.Format("#{0:X2}{1:X2}{2:X2}", colorObj.R, colorObj.G, colorObj.B) End Function
Set the color property expression on the report object you want set the color of to this
=Code.GetMyColour(First(Fields!RecipeColour.Value, "StockControl"))
来源:https://stackoverflow.com/questions/5206115/how-do-i-color-a-label-in-reporting-services-based-on-a-value-in-the-dataset