GridView突出特定单元格

来源:互联网 发布:鲍里斯约翰逊知乎 编辑:程序博客网 时间:2024/04/29 10:08

/绑定
        public void Bind()
        {
            DataClasses1DataContext uidc = new DataClasses1DataContext("Data Source=1-51ad74db663f4;Initial Catalog=LinqWeb;User ID=zhouyong;pwd=1314");
            var p = from c in uidc.user_info select new { 编号 = c.userId, 姓名 = c.userName, 年龄 = c.userAge, 性别 = c.userSex };
            this.gvw.DataSource = p;
            this.gvw.DataBind();
            
            //突出特定格
            for (int i = 0; i < (this.gvw.Rows.Count); i++)
            {
                int age = Convert.ToInt32(this.gvw.Rows[i].Cells[8].Text.ToString());
                if (age < 22)
                {
                    this.gvw.Rows[i].Cells[8].BackColor = System.Drawing.Color.Red;
                }
            }
        }

原创粉丝点击