protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {//我们先设置当鼠标上去的时候他的背景色改变 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#ff6699'"); //下面我们再设置当鼠标离开后背景色再还原 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;"); //为特定的数改变行样式这也是在这个事件里面,因为这个事件是在数据被绑定的时候执行的 // for (int i = 0; i < GridView1.Rows.Count; i++) { //为了对全部数据行都有用,我们使用循环 //string lbl = Convert.ToString(DataBinder.Eval(e.Row.DataItem,"state")); //我们得取出行中state字段绑定的值,用他作为判断条件 //if (lbl == "BB") if (e.Row.RowIndex % 2 == 1) { //如果他的值等于BB,那么 e.Row.BackColor = Color.LimeGreen; //给当前行的背景色赋值,说心理话,微软这点没DW做得好,人家就是直观得好 } } }