老师好:
   我在datagrid中显示的是一个带有日期(星期)的数据表,我想做到使满足于某个特定日期(例如周日、元旦)的行显示的格式为红色,或者仅日期单元格(cell)显示为红色?我应该如何设置?
  我用vb.  在为datagrid填充数据后,应该编辑datagrid.item.style.add?还是应该如何?请指教        谢谢

解决方案 »

  1.   

    我只会用c#写:
    if (e.Item.ItemIndex >= 0)
    {
    if (e.Item.Cells[0].Text=="2001-1-1")
    {
    e.Item.Attributes.Add("style","font:32px;");
    }
    }
      

  2.   

    当然根据你的条件设置其Style属性即可.
      

  3.   

    Private Sub FormatDataGrid_ItemDataBound(ByVal sender As Object,_
       ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles FormatDataGrid.ItemDataBound    ' 确保处理的是数据行,而不是Header或者Footer
        If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
          '  得到Manager字段的值
          Dim isManager As String = CType(DataBinder.Eval(e.Item.DataItem, "Manager"), String)      If isManager = "1" Then
            '  设定文字和背景颜色
            e.Item.Cells(2).Text = "经理"
            e.Item.Cells(2).Style.Add("font-weight", "bold")
            e.Item.Cells(2).ForeColor = System.Drawing.Color.Red
            e.Item.BackColor = System.Drawing.Color.AliceBlue
          Else
            e.Item.Cells(2).Text = "普通员工"
          End If
        End If
      End Sub参照
    http://dotnet.aspx.cc/ShowDetail.aspx?id=F73EF6AD-6878-4748-B963-5181252E5AED