HTML does not contain an attribute called
CssClass
.
ASP.NET controls contain a
property called
CssClass
, which maps to the HTML attribute called
class
. This attribute contains a list of class names defined in your CSS file(s). The styles for those CSS classes will be applied to the element.
The value you're supplying is not a CSS class name; it is an inline style definition. Therefore, you need to use the
style
attribute:
data.Attributes["style"] = "text-decoration:line-through; color:red;";
Alternatively, you could use the
Style
property:
data.Style["text-decoration"] = "line-through";
data.Style["color"] = "red";
You'll also need to retrieve the text of the "StrikeLabel" control; calling
.ToString()
on it will only return the type name.
The text will most likely be
"True"
, which is not the same value as
"true"
, so you'll need to modify your test.
Label strikeLabel = (Label)e.Item.FindControl("StrikeLabel");
string strike = (strikeLabel != null) ? strikeLabel.Text : string.Empty;
if (string.Equals(strike, "True", StringComparison.OrdinalIgnoreCase))
{
...
}