add cssclass to label in panel in datalist
I had label in panel in datalist and I added code in item da开发者_JAVA技巧tabound for datalist to add cssclass to label if specific condition the code work well and I find label but the cssclass hadnot make any action on label.and I didnot know what is wrong?
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
string LanguageID = Globals.GetSuitableLanguage(Page);
Label lbl = e.Item.FindControl("LblText") as Label;
Panel Pnl = e.Item.FindControl("pnlModal") as Panel;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
LblHead = e.Item.FindControl("Label1") as Label;
}
if (LblHead != null && LanguageID == "ar")
{
LblHead.Attributes.Add("CssClass", "hed_logo2");
}
}
CssClass is what the asp.net runtime calls the css class that is applied to an element. However, when you are using the Attributes
collection, you are emiting values straight to the HTML of the element.
In most cases, the asp.net and the html names of the attributes are equal (name, title...), however there are lots of small differences. The attribute that is the applied css class, is called CssClass
in asp.net, and simply class
in html dom.
So instead of
LblHead.Attributes.Add("CssClass", "hed_logo2");
just write
LblHead.Attributes.Add("class", "hed_logo2");
and that should fix the issue.
精彩评论