Reputation: 478
I create a label and set his TEXT color to red. I use ForeColor property but with him not working :(
This is my UI:
This is my label code:
Label reqF = new Label();
reqF.Text = "*";
reqF.ForeColor = System.Drawing.Color.Red;
reqF.CssClass = "formvalidation";
reqF.Font.Size = 15; // 15px
This is my string code:
TableHeaderCell header1 = new TableHeaderCell();
header1.Text = "Destination" + reqF.Text; <----------- My label
tRow0.Cells.Add(header1);
Upvotes: 2
Views: 3181
Reputation: 66641
In this line
header1.Text = "Destination" + reqF.Text;
you add only the text (*) to the destination, not the full div with the style on.
The easiest (and faster) way is to direct add the style online as:
header1.Text = "Destination <span style=\"color=red\">*</span>" ;
Upvotes: 2
Reputation: 56688
You are only using text of the control, not the whole control with styling. Your code should actually look something like that:
TableHeaderCell header1 = new TableHeaderCell();
LiteralControl literal = new LiteralControl();
literal.Text = "Destination";
header1.Controls.Add(literal);
header1.Controls.Add(reqF);
tRow0.Cells.Add(header1);
Note that here Literal
control is used to insert the Description
string, and then the whole Label with the *
is being inserted.
Upvotes: 1