We help IT Professionals succeed at work.
Get Started

Bind a label's backcolor to a database field

nmcdermaid
nmcdermaid asked
on
1,325 Views
Last Modified: 2013-11-26
Hi,

Using ASP.Net and Visual Studio 2005, I am attempting to dynamically change the backgournd colour of a label.

In the smart tag for the Label, I have selected 'Edit Databindings'
Then I have selected the Backcolor property, and assigned to a column (WebColour) from my table.

It has added this code to my label tags:

Backcolor='<%# Eval("WebColour) %>'


I've tried three different data formats in my table:

#000000
000000
0

All of them result in a 'specified cast is not valid' error at the backcolor tag.


When I type

? Eval("WebColour)

in the command window I see the exact data that I am expecting.


Can anyone tell me what format this needs to be in in that database?

Also can you tell me what the # symbol is doing in the statement... I understand the rest.


The label is inside a FormView control which is working fine in every other way.


Comment
Watch Question
This problem has been solved!
Unlock 3 Answers and 10 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE