其樂

勤能补拙

  博客园 :: 首页 :: 联系 :: 订阅 订阅 :: 管理
  7 Posts :: 21 Stories :: 4 Comments :: 0 Trackbacks

公告

在DataGrid中让不同条件的行显示不同的背景颜色

通过如下方法做时:在DataGrid的ItemDataBind事件里写
if((e.Item.Cells[6].Text)=="男")//假设性别字段在第6行
  e.Item.BackColor=Color.Blue;
if((e.Item.Cells[6].Text)=="女")
  e.Item.BackColor=Color.Red;
有没有具体的例子?我这样一来做了,但没有任何效果。我的做法是写了
private void change_color(Object sender, DataGridItemEventArgs e) {
        if((e.Item.Cells[1].Text)=="男")//假设性别字段在第6行
            e.Item.BackColor=Color.Blue;
        if((e.Item.Cells[1].Text)=="女")
            e.Item.BackColor=Color.Red;

           
}
posted on 2005-09-12 11:07 其樂 阅读(277) 评论(0)  编辑 收藏