tags:

views:

16

answers:

1

I had datalist and My manger told me when user select item in datalist this item must have css or color .I did my code but it didnot work well and this error apeared ( Operator == cannot be applied to operands of type System.Web.UI.WebControls.ListItemType and System.Web.UI.WebControls.DataControlRowType )

protected void DataList3_ItemDataBound(object sender, DataListItemEventArgs e)
{
    {
       if (e.Item.ItemType == DataControlRowType.DataRow)
       {
           e.Item.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
           e.Item.Attributes["onmouseout"] = "this.style.textDecoration='none';";

           e.Item.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.DataList3, "Select$" + e.Item.ItemIndex);
        }
    }
}
+1  A: 

e.Item is a DataListItem; if you check its ItemType property, you'll see that it's a ListItemType, so you should use that enumeration.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listitemtype.aspx

Something like:

if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem)
Dan Dumitru