Gridview鼠标选定颜色和具体列颜色

来源:互联网 发布:java web微信支付demo 编辑:程序博客网 时间:2024/05/19 21:41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor='red';");
            e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=c");
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count; i++)
        {
            string lbl = Convert.ToString(DataBinder.Eval(e.Row.DataItem,"state"));
            if (lbl == "CA")
            {
                e.Row.BackColor = System.Drawing.Color.Blue;
            }
        }
    }
}

原创粉丝点击