System.Drawing.Color tmp = e.Item.BackColor;

解决方案 »

  1.   

    DataGrid1_ItemDataBound:
    if(e.Item.ItemType == ListItemType.Item)//普通项
    {
       System.Drawing.Color tmp1 = e.Item.BackColor;}
    if(e.Item.ItemType == ListItemType.AlternatingItem)//交替项
    {
       System.Drawing.Color tmp2 = e.Item.BackColor;}
      

  2.   

    问题还未解决,查看生成的HTML代码如下,Color [Empty]为所取出的值
    --------------------------------------------------------------------------------------
    <tr onmouseout="this.style.backgroundColor='Color [Empty]'" onmouseover="this.style.backgroundColor='#C0C0FF'" style="color:#4A3C8C;background-color:#E7E7FF;">
    --------------------------------------------------------------------------------------
    但我想要的是style="color:#4A3C8C;background-color:#E7E7FF;"中的background-color:#E7E7FF,有办法取出来吗?
      

  3.   

    System.Data.DataRowView DV;
    DV=null;
    //絪胯篈┪獶絪胯篈
    if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.EditItem)
    {
    DV=(System.Data.DataRowView)e.Item.DataItem;
    System.Web.UI.WebControls.LinkButton lbn;
    lbn=(System.Web.UI.WebControls.LinkButton) e.Item.Cells[1].Controls[0];
    lbn.Attributes.Add("onclick","return confirm('絋﹚埃赣魁[emp_no:"+DV["emp_no"].ToString().Trim()+"]盾?');"); e.Item.Attributes.Add("style", "bgColor:'#33ff33';");
    e.Item.Attributes.Add("onmouseover", "javascript:this.bgColor='#33ff33';");
    e.Item.Attributes.Add("onmouseout","javascript:this.bgColor='#00cc99';");
      

  4.   

    我设置的DataGrid是交替颜色的,从自动产生的代码看一行是
    <tr style="background-color:#E7E7FF">
    另一行,是
    <tr style="background-color:#7E7EFF">
    我现在想在ItemDataBound事件里取出tr的background-color,然后添加
    e.Item.Attributes.Add("onmouseout","javascript:this.bgColor='取出来的颜色值'")
    但是死活取不出正确的tr的background-color
    有什么办法吗?
      

  5.   

    DataGrid太烂,我用自己写的Grid
      

  6.   

    Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)        
        If e.Item.ItemType = ListItemType.Item Or   e.Item.ItemType = ListItemType.AlternatingItem Then       
        e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'")        
        e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")            End If      
      End Sub
      

  7.   

    但假如不是在DataGrid1_ItemDataBound里面写怎么办?是在PAGE_LOAD里面怎么写?
      

  8.   

    private void AddCustomDataTableStyle()
       {
          DataGridTableStyle ts1 = new DataGridTableStyle();
          ts1.MappingName = "Customers";
          // Set other properties.
          ts1.AlternatingBackColor = Color.LightGray;      /* Add a GridColumnStyle and set its MappingName 
          to the name of a DataColumn in the DataTable. 
          Set the HeaderText and Width properties. */
          
          DataGridColumnStyle boolCol = new DataGridBoolColumn();
          boolCol.MappingName = "Current";
          boolCol.HeaderText = "IsCurrent Customer";
          boolCol.Width = 150;
          ts1.GridColumnStyles.Add(boolCol);
          
          // Add a second column style.
          DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
          TextCol.MappingName = "custName";
          TextCol.HeaderText = "Customer Name";
          TextCol.Width = 250;
          ts1.GridColumnStyles.Add(TextCol);      /* Add the DataGridTableStyle instances to 
          the GridTableStylesCollection. */
          myDataGrid.TableStyles.Add(ts1);
       }
    设置颜色代码:     ts1.AlternatingBackColor = Color.LightGray;