天天看點

背景給GridView添加行的樣式

 protected void gvMoreSize_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

for (int j = 0; j < this.gvMoreSize.Rows.Count + 1; j++)

            {

                //首先判斷是否是資料行

                if (e.Row.RowType == DataControlRowType.DataRow)

                {

                    //當滑鼠停留時更改背景色

                    e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.color='#116a79';this.style.backgroundColor='#cef97b'");

                    //當滑鼠移開時還原背景色

                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;this.style.color='#3a6381'");

                    e.Row.Attributes["style"] = "Cursor:pointer";

                }

            }

}

c#