No 34 · 鼠标移动改变表格行的颜色

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //如果当前项不为空
        if (e.Row.RowIndex != -1)
        {
            //取得当前项的索引值加1,因为项的索引值是从0开始的
            int orderID = e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = orderID.ToString();
        }

       //点击表格打开
        if (e.Row.RowType == DataControlRowType.DataRow)
         {
            
             e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");
             e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='';this.style.color='';");
         }

        }

你可能感兴趣的:(object)