Hey guys,
How do you set the forecolor of a label progmatically???

Recommended Answers

All 4 Replies

For an ASP label in c# code?

Drop a label in the designer:

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

Assign a forecolor in code:

protected void Page_Load(object sender, EventArgs e)
    {
      Label1.ForeColor = System.Drawing.Color.Red;
    }

lbl.ForeColor = System.Drawing.ColorTranslator.FromHtml("#9AFE2E");

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

[B]//Reference for setting  color
using System.Drawing;[/B]

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
[B]        Label1.ForeColor = Color.Yellow ;
        Label1.BackColor = Color.Black ;[/B]
    }
}

Hey guys,
How do you set the forecolor of a label progmatically???

Use the following code to change the color of a label

Label1.ForeColor = Drawing.Color.Red
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.