DataGridTableStyle style=new DataGridTableStyle();
style.MappingName=ds.Tables[0].TableName;
style.AlternatingBackColor=System.Drawing.Color.Lavender;;

解决方案 »

  1.   

    我不是说怎么为他上颜色,而是问,如何区分两行.<一行白一行黑,如何判断行颜色切换?>
      

  2.   

    http://www.codeproject.com/csharp/custom_datagridcolumnstyl.asp?target=datagrid
      

  3.   

    public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn 
     
         { 
     
              protected override void Paint(System.Drawing.Graphics g, 
     
                   System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager 
     
                   source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush 
     
                   foreBrush, bool alignToRight) 
     
              { 
     
              // the idea is to conditionally set the foreBrush and/or backbrush 
     
              // depending upon some crireria on the cell value 
     
              // Here, we color anything that begins with a letter higher than 'F' 
     
                   try{ 
     
                        object o = this.GetColumnValueAtRow(source, rowNum); 
     
                        if( o!= null) 
     
                        { 
     
                             char c = ((string)o)[0]; 
     
                             if( c > 'F') 
     
                             { 
     
                             // could be as simple as 
     
                             // backBrush = new SolidBrush(Color.Pink); 
     
                             // or something fancier... 
     
                                  backBrush = new LinearGradientBrush(bounds, 
     
                                       Color.FromArgb(255, 200, 200), 
     
                                       Color.FromArgb(128, 20, 20), 
     
                                       LinearGradientMode.BackwardDiagonal); 
     
                                  foreBrush = new SolidBrush(Color.White); 
     
                             } 
     
                        } 
     
                   } 
     
                    catch(Exception ex){ /* empty catch */ } 
     
                   finally{ 
     
                        // make sure the base class gets called to do the drawing with 
     
                        // the possibly changed brushes 
     
                        base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight); 
     
                   } 
     
              } 
     
         } 
     
      

  4.   

    http://lucky_elove.www1.dotnetplayground.com/ShowList.aspx?id=1
      

  5.   

    在DataGridResult_ItemDataBound事件里用  e.Item.ItemIndex 整除2判断
      

  6.   

    请问DATALIST有类似的事件吗?再一个,如何通过此事件更新记录中的其它控件,假设,显示每条记录中有一个LABEL控件,如何让此控件显示的数为e.Item.ItemIndex,现二个,背景颜色如何从此事件中调用.也有每条记录的背景颜色.
      

  7.   

    TO:net_lover(孟子E章)
    http://lucky_elove.www1.dotnetplayground.com/ShowList.aspx?id=1
    没有我要的东西.谢谢!静待您的详细解释.先谢过!
      

  8.   

    你是要一行黑一行白?还是每一行都不同,是前者还有办法,
    this.dataGrid.AlternatingBackColor = System.Drawing.Color.LightGray;