Give inline css to any page element in c# code behind

.apsx

.aspx.cs
if (lblName.Text== "Muhammad Ali")
{
lblName.Style.Add("color", "green");
}
else
{
lblName.Style.Add("color", "red");
}

The above lines of code segment are self explanatory. I am checking that if name is Muhammad Ali then asp:Label color will be green else color will be red. Simply I use built-in Add function of Style class to give inline css to asp:Label in c# code behind.

0 comments:

Post a Comment