把这一列的visiable设为false不显示.但在程序中还是可以用的

解决方案 »

  1.   

    在OnItemDataBound事件中:
    这是我的:
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){
    String ContractName = DataBinder.Eval(e.Item.DataItem, "ContractName").ToString();
    e.Item.Cells[0].ToolTip = ContractName;
              DateTime date1 = DateTime.Parse(e.Item.Cells[4].Text);
      string Result = e.Item.Cells[5].Text;
      DateTime now = DateTime.Today;
      TimeSpan diff1 = date1 - now ;
      int days = (int)diff1.Days;
      if((days < 3)&&(Result == "执行中")) {
              int numj=e.Item.Cells.Count;
              for(int j=0;j<numj;j++)
              {
              e.Item.Cells[j].ForeColor=Color.Black;
              e.Item.Cells[j].Font.Bold=false;
                  e.Item.Cells[5].BackColor = Color.Red;
                       }
     }
      

  2.   

    Question: How do I conditionally set the backcolor of a cell in my Datagrid based on a value from the database? (conditional formatting) Answer: Handle this in the ItemDataBound event, where you can access the DataItem as it is bound to the Datagrid, and the Cells() collection of the current Datagrid item. Sub Datagrid1_ItemDataBound(source As Object, e As DataGridItemEventArgs)
      If (e.Item.ItemType = ListItemType.Item Or _
        e.Item.ItemType = ListItemType.AlternatingItem) Then
        If Convert.ToDateTime(e.Item.Cells(1).Text) < DateTime.Today Then _
        e.Item.Cells(1).BackColor = System.Drawing.Color.FromName("#ffccff")
        If e.Item.DataItem("UserID") = 590 Then _
        e.Item.Cells(2).BackColor = System.Drawing.Color.DeepPink
      End If
    End Sub
      

  3.   

    if((e.Item.Cells[6].Text)=="&Auml;&ETH;")//
      e.Item.BackColor=Color.Blue;
    if((e.Item.Cells[6].Text)=="&Aring;&reg;")
      e.Item.BackColor=Color.Red;
    private void change_color(Object sender, DataGridItemEventArgs e) {
            if((e.Item.Cells[1].Text)=="&Auml;&ETH;")//
                e.Item.BackColor=Color.Blue;
            if((e.Item.Cells[1].Text)=="&Aring;&reg;")
                e.Item.BackColor=Color.Red;            
    }http://www.csdn.net/expert/topic/733/733305.xml?temp=.9916498