天天看點

ASP.NET2.0下為GridView添加滑鼠滑過(onmouseover、onmouseout)的行顔色高亮效果!

<script type="text/javascript">function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script> protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        //将滿足特定條件的行标為高亮

        if (e.Row.RowType == DataControlRowType.DataRow)//判定目前的行是否屬于datarow類型的行

        {

            int money = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "MONEY"));//取目前行的列值

            if (money == 77)

                e.Row.BackColor = Color.Red;

            //string customer = (string)DataBinder.Eval(e.Row.DataItem, "CUSTOMER");

            string customer = DataBinder.Eval(e.Row.DataItem, "CUSTOMER").ToString();

            if (customer == "sdf")

                e.Row.BackColor = Color.Red;

        }

        //加入滑鼠滑過的高亮效果

        if (e.Row.RowType == DataControlRowType.DataRow)//判定目前的行是否屬于datarow類型的行

        {

            //當滑鼠放上去的時候 先儲存目前行的背景顔色 并給附一顔色

            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow',this.style.fontWeight='';");

            //當滑鼠離開的時候 将背景顔色還原的以前的顔色

            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';"); 

        }

        //單擊行改變行背景顔色

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

        {

           e.Row.Attributes.Add("onclick","this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");

        }