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;