datagrid 上面的行的光亮条跟随鼠标移动

if ((e.Item.ItemType==ListItemType.Item)||(e.Item.ItemType==ListItemType.AlternatingItem)) 
            

                e.Item.Attributes.Add(
"onmouseover""this.style.backgroundColor='#ffffcc';this.style.color='buttontext';this.style.cursor='default';"); 
                
//e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=this.getAttribute('BKC');"); 
                e.Item.Attributes.Add("onmouseout""this.style.backgroundColor='';this.style.color='';"); 
            }
  
可以实现光亮条的选择 

设置指定行的颜色
   
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        
{
            
if (e.Item.ItemIndex == (i_currentline-1))
            
{
                e.Item.BackColor 
= System.Drawing.Color.Yellow;
            }

        }

行颜色交替显示:



在DataGrid 里面的ItemDataBound事件


  
//颜色交替显示
        if (e.Item.ItemIndex >= 0 && e.Item.DataItem is DataRowView)
        
{
            DataRowView row 
= (DataRowView)e.Item.DataItem;
            
int numj = e.Item.Cells.Count;
            
for (int j = 0; j < numj; j++)
            
{
                e.Item.Cells[j].ForeColor 
= System.Drawing.Color.Black;
                e.Item.Cells[j].BackColor 
= System.Drawing.Color.SkyBlue;
            }

        }

posted on 2006-12-19 11:36  玄新  阅读(164)  评论(0编辑  收藏  举报

导航