GridView实现光棒效果

// JScript 文件

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';
}

 

后台代码

using System.Drawing;

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

    //注册JS事件
    protected void EnClientScript()
    {
       if (!ClientScript.IsClientScriptIncludeRegistered(this.GetType(),"HighLight"))
       {
           Page.ClientScript.RegisterClientScriptInclude("HighLight", "http://www.cnblogs.com/jscript/HighLight.js");
       }

    }

 

  //数据行建立事件
    protected void GridView1_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 @ 2009-08-20 09:56  天涯之巅  阅读(843)  评论(0编辑  收藏  举报