开发者

How do I Color a label in reporting services based on a value in the dataset?

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 pro开发者_开发问答perty, but I can't embed c# there.

Thanks!


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.


After some digging I found out that u have to use VB code.

Here's the steps.

  1. Add a reference to System.Drawing in the report properties -> reference tab
  2. 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

  3. Set the color property expression on the report object you want set the color of to this

    =Code.GetMyColour(First(Fields!RecipeColour.Value, "StockControl"))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜