GridView注册单双击事件

存在问题:由于双击之前会触发单击,从而无法注册双击事件。

解决思路:如何在点击一次后在N秒内未再次点击,将视为单击,否则为双击

js:

    function ClickMouse(url)
    {   
        var msgID=url;
        var expiration =new Date((new Date).getTime()+1000*60000);   
        document.cookie="msgID="+msgID+";expires="+expiration.toGMTString()+";path=/";
         //触发后台Button1按钮事件,延迟时间为1秒
        setTimeout("__doPostBack('Button1','')",1000);
    }

c#:

        protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
       
            if (e.Row.Cells.Count > 0) e.Row.Cells[0].Style.Add("display", "none");
            if (e.Row.Cells.Count > 1) e.Row.Cells[1].Style.Add("display", "none");
            if (e.Row.Cells.Count > 3) e.Row.Cells[3].Style.Add("display", "none");
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("ondblclick", this.Page.GetPostBackClientEvent(this, "4;" + e.Row.Cells[1].Text+";双"));
                string url = "4," + e.Row.Cells[1].Text + "," + e.Row.Cells[0].Text;
                e.Row.Attributes["onclick"] = "javascript:ClickMouse('" + url + "')";
              
                e.Row.Cells[2].Attributes.Add("title", e.Row.Cells[2].Text);
                if (e.Row.Cells[2].Text.Length > 40)
                {
                    e.Row.Cells[2].Text = e.Row.Cells[2].Text.Substring(0, 40) + "...";
                }
            }
        }

双击:

    public void RaisePostBackEvent(string eventArgument)
    {
    }

单击:

protected void Button1_Click(object sender, EventArgs e)
    {
    }

 

除此之为也可以通过在GridView列上注册事件

if (GVt.Rows.Count > 0)
        {
            for (int i = 0; i < GV.Rows.Count; i++)
            {

                   GV.Rows[i].Cells[3].Attributes.Add("onclick", "ClickMouse('" + url + "')");

                    GV.Rows[i].Cells[4].Attributes.Add("onclick", "ClickMouse('" + url + "')");

                    GV.Rows[i].Cells[5].Attributes.Add("onclick", "ClickMouse('" + url + "')");

                    GV.Rows[i].Style.Add("cursor", "hand");

             }

         }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值