zoukankan      html  css  js  c++  java
  • Gridview应用技巧——如何为行添加事件

    Gridview应用技巧——如何为行添加事件收藏

    下面的代码实现了如何为Gridview添加鼠标经过、离开、单击、双击的事件 

     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                e.Row.Attributes.Add("BorderColor ", "#d2d2d2");
                e.Row.Style.Add("Height","8px");
                e.Row.Style.Add("FontSize","8");
                e.Row.Style.Add("VerticalAlign", "Middle");
               
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                  
                    string SelectID = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();//((ClientList)(e.Row.DataItem)).ClientID;
                    if (!String.IsNullOrEmpty(SelectID))
                    {
                        //鼠标双击Row时的效果
                        e.Row.Attributes.Add("ondblclick", "javascript:window.location.href='"+(string)ViewState["Href"]+"?ID=" + SelectID+ "';");
                        //鼠标经过Row时的效果
                        e.Row.Attributes.Add("onmouseover", "this.classname=onColor2(this)");
                        //鼠标离开Row时的效果
                        e.Row.Attributes.Add("onmouseout", "this.classname=offColor2(this)");
                        //鼠标键Row时的效果
                        e.Row.Attributes.Add("onmousedown", "this.classname=downColor(this," + SelectID + ")");
                    }
                 
                }

    }

    下面是JavaScript方法

    function onColor2(td)
    {
    // td.style.backgroundColor="#c0c0c0";
    // td.style.fontWeight="bold";
    // td.style.fontStyle="italic";
     td.style.color="#0600FF";
    }

    function offColor2(td)
    {
    // td.style.backgroundColor="";
    // td.style.fontWeight='';
    // td.style.fontStyle='';
     td.style.color='';
     //td.style.backgroundColor='';
    }
    function downColor(td,a)
    {
    // td.style.backgroundColor="";
    // td.style.fontWeight='';
    // td.style.fontStyle='';
    var   rowindex   =   td.rowIndex;
     for(var   i=1;i <td.parentElement.rows.length;i++)
     {
              if(i!=rowindex)
               {

                   //当选中其它行时,要把另外所有行的背景色去掉
                    td.parentElement.rows[i].style.color='';
                    td.parentElement.rows[i].style.backgroundColor   =   '';
               }
      }
        document.getElementById("hid").value=a;
     td.style.color='#0600FF';
     td.style.backgroundColor='#FFDE59';
    }

    作者:wpf之家
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    MyBatis:2
    MyBatis:1
    synchronized锁普通方法和锁静态方法
    打印倒直角三角形
    迭代器模拟for循环
    Python迭代对象与迭代器
    ffmpeg用法(心得体会还有你见过的用法)
    ffmpeg命令选项解释
    ffmpeg一些filter用法、以及一些功能命令
    FFMPEG 实现 YUV,RGB各种图像原始数据之间的转换(swscale)
  • 原文地址:https://www.cnblogs.com/wpf123/p/2347472.html
Copyright © 2011-2022 走看看