1.js文件:HeightLight.JS

function onmouseoutColor1(source)
{
    source.style.backgroundColor='#fffbd6';
    source.style.color='black';
}

function onmouseoverColor1(source)
{
    source.style.backgroundColor='#C0C0FF';
    source.style.color='#ffffff';
}

function onmouseoutColor2(source)
{
    source.style.backgroundColor='#FFFFFF';
    source.style.color='black';
}

function onmouseoverColor2(source)
{
    source.style.backgroundColor='#C0C0FF';
    source.style.color='#ffffff';
}

 

2. CodeBehind文件(前台已绑定一个GridView)

  

 private int lineNO = 0;//0为奇数列,1为偶数列

 protected void Page_Load(object sender, EventArgs e)
 {
  if (!IsPostBack)
  {
   if (!ClientScript.IsClientScriptIncludeRegistered(this.GetType(),"HighLight"))
   {
    Page.ClientScript.RegisterClientScriptInclude("HighLight","./Scripts/HighLight.js");
   }
  }
    }

 //数据行建立事件
 protected void gviewEmployees_RowDataBound(object sender, GridViewRowEventArgs e)
 {

  switch (e.Row.RowType)
  {
   case DataControlRowType.Header:
    e.Row.BackColor = Color.FromArgb(153,0,0);
    e.Row.ForeColor = Color.White;
    break;
   case DataControlRowType.DataRow:
    if (lineNO == 0)
    {
     e.Row.BackColor = Color.FromArgb(255, 251, 214);
     e.Row.Attributes.Add("onmouseout", "onmouseoutColor1(this);");
     e.Row.Attributes.Add("onmouseover", "onmouseoverColor1(this);");

     lineNO = 1;
    }
    else
    {
     e.Row.BackColor = Color.White;
     e.Row.Attributes.Add("onmouseout", "onmouseoutColor2(this);");
     e.Row.Attributes.Add("onmouseover", "onmouseoverColor2(this);");

     lineNO = 0;
    }
    break;
  }
 }

 

posted on 2008-07-26 23:29  朱胜  阅读(755)  评论(0编辑  收藏  举报