This is a migrated thread and some comments may be shown as answers.

Dynamic Color (value from database)?

4 Answers 532 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Heath Brown
Top achievements
Rank 1
Heath Brown asked on 14 Apr 2010, 09:39 PM
Hello,

I am currently working on some reports that are dynamic and change based on which company is viewing the reports.  The logo changes to the company's logo, and each company has a main color and alt color that is customizable from the database.  I'm creating these features from scratch, so I just need to know how to do it correctly.

So far, I've been able to bind the logo (picturebox) to data that is a URL of type nvarchar(255) in the database.  I can then change companies and the logo is definately changing to the company it is set to in the database.

The problem is I have two columns in the company table that define the two custom colors.  One is ReportColorMain and the other is ReportColorAlt.  Right now I have them set to data type nvarchar(25) and just put some RGB color values in them (like "0, 97, 178").  I have also tried to use color names like Crimson or DarkRed.  I bind these to either the backcolor or color attribute of the particular object in the report I want to use this color with.  Unfortunately, it is not working like the logo did.  I'm getting a report error:

An error has occured while processing TextBox '':  
Bindings error - An error occured while invocing the setter on property 'Style.Color' with value 'DarkRed' 

Do I have to use a certain datatype in my SQL Server 2005 database instead of nvarchar?  Should I use some other method of collecting this color from the database?  Help would be greatly appreciated!

4 Answers, 1 is accepted

Sort by
0
Heath Brown
Top achievements
Rank 1
answered on 15 Apr 2010, 06:19 PM
Could I get some help with this?  Should I submit a ticket instead?
0
Tony
Top achievements
Rank 2
answered on 15 Apr 2010, 10:43 PM
can you post the code that is giving you the error?
0
Heath Brown
Top achievements
Rank 1
answered on 16 Apr 2010, 12:54 AM
The only custom code I have is for the web browser page for filtering the data by certificateID.

public partial class Default : System.Web.UI.Page   
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        string query = (string)Request.QueryString["CertificateID"];  
        if (query != null)  
        {  
            Telerik.Reporting.Report report = (Telerik.Reporting.Report)this.ReportViewer1.Report;  
            report.ReportParameters["CertificateID"].Value = query;  
        }  
    }  

That is working fine and isn't part of the issue.  The stuff mentioned in the original post was all done within the report designer.  I bound the background color to a field (mentioned above) in the database that is nvarchar.  I can do that with the picturebox value being a URL to the image, but when I bind a textbox or anything else to a color value and then use something like "128, 128, 128" or "DarkRed" in the database, I get the error shown in my first post.
-1
Peter
Telerik team
answered on 19 Apr 2010, 05:04 PM
Hi Heath Brown,

As explained in the Bindings help article - to bind Style.BackgroundColor property of a report item you have to utilize an User Function that returns struct System.Drawing.Color. Check out the sample User Function in the following code snippet:

public static System.Drawing.Color ColorFromValue(string value)
{
    System.Drawing.Color selectedColor;
    switch (value)
    {
        case "Red":
            selectedColor = System.Drawing.Color.Red;
            break;
        default:
            selectedColor = System.Drawing.Color.Blue;
            break;
    }
    return selectedColor;
}


Sincerely yours,
Peter
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
Heath Brown
Top achievements
Rank 1
Answers by
Heath Brown
Top achievements
Rank 1
Tony
Top achievements
Rank 2
Peter
Telerik team
Share this question
or