我有一张记录用户留言的数据表,其中一列[Checked]记录留言是否被阅读过。我希望当GridView列出所有留言时,根据[Checked]的值按不同格式显示数据行。请问怎样实现?谢谢

解决方案 »

  1.   

    在DataGrid中我是这样写的:
    在绑定事件DataGrid1_ItemDataBound时
    if(e.ItemIndex != -1)
    {
      if(e.Item.Cells[2].Text == 0)//没被选中
      {
          e.Item.Cells[2].ForeColor = Color.red;//这个单元格的前景色
         //e.Item.ForeColor = Color.Blue;//整行的前景色
      }}
      

  2.   

    if(e.ItemIndex != -1)
    这句写错了。
    应该是: if(e.Item.ItemIndex != -1)
      

  3.   

    我最后用的方法是:foreach (GridViewRow s in GridView1.Rows)
            {
                if (GridView1.DataKeys[s.DataItemIndex].Values["Checked"].ToString()=="False") s.ForeColor=System.Drawing.Color.Red;
            }