How to implement conditional formatting in a GridView

前端 未结 4 1369
礼貌的吻别
礼貌的吻别 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:37

    With BoundField you should modify your Item class.

    If you don't want to modify your CodeBehind ther is a sort of trick you can do using a TemplateField:

            
            
                
                
                    
                        
                    
                
            
        
    

    obviously you can do it for any type of object but maybe your "Text" field would become.. complicated..

    by the way.. my CodeBehind for this example was just you class Item and this Page_Load():

        protected void Page_Load(object sender, EventArgs e)
        {
            Item i1 = new Item();
            i1.ItemName = "name1";
            i1.ItemValue = "foo";
            Item i2 = new Item();
            i2.ItemName = "name2";
            i2.ItemValue = DateTime.Now;
            List list1 = new List();
            list1.Add(i1);
            list1.Add(i2);
            MyTable.DataSource = list1;
            MyTable.DataBind();
        }
    

    and the result was correct ;)

提交回复
热议问题