How to implement conditional formatting in a GridView

前端 未结 4 1392
礼貌的吻别
礼貌的吻别 2021-01-18 21:55

I have a GridView on my aspx page which displays a collection of objects defined by the following class

public class Item
{
    public string ItemName{get; s         


        
4条回答
  •  春和景丽
    2021-01-18 22:48

    i decided with the Paul Rowland solution and more one thing "if (e.Item.DataItem is DataRowView)":

        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==                 ListItemType.AlternatingItem))
         {
           if (e.Item.DataItem is DataRowView)
           {
             DataRowView rowView = (DataRowView)e.Item.DataItem;
             String state = rowView[PutYourColumnHere].ToString();
             if (state.Equals("PutYourConditionHere"))
             {
               //your formating, in my case....
               e.Item.CssClass = "someClass";
             }
           }
         }
    

提交回复
热议问题