C# 在单击和双击时隐藏/显示链接按钮

C# 在单击和双击时隐藏/显示链接按钮,c#,asp.net,gridview,linkbutton,C#,Asp.net,Gridview,Linkbutton,当我在gridview行上单击一次时,以及当我双击仅显示更新时,只需显示删除链接按钮 html代码 <ItemTemplate> <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("itemCode") %>'

当我在gridview行上单击一次时,以及当我双击仅显示更新时,只需显示删除链接按钮

html代码

                            <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1"
                                CommandArgument='<%# Eval("itemCode") %>'
                                CommandName="DeleteRow" runat="server" >Delete</asp:LinkButton>
                            <asp:LinkButton ID="LinkButton2"
                                CommandArgument='<%# Eval("itemCode") %>'
                                CommandName="Update" runat="server">Update</asp:LinkButton>
                        </ItemTemplate>
我通过检查300毫秒后是否有双击来区分单击和双击。当它是双击时,我只需要显示更新按钮,然后单击删除

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // Get the LinkButton control in the first cell
            LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
            // Get the javascript which is assigned to this LinkButton
            string _jsSingle =
            ClientScript.GetPostBackClientHyperlink(_singleClickButton, "");
            // To prevent the first click from posting back immediately
            // (therefore giving the user a chance to double click) 
            // pause the postbackfor 300 milliseconds by 
            // wrapping the postback command in a setTimeout
            _jsSingle = _jsSingle.Insert(11, "setTimeout(\"");
            _jsSingle += "\", 300)";
            // Add this javascript to the onclick Attribute of the row
            e.Row.Attributes["onclick"] = _jsSingle;

            // Get the LinkButton control in the second cell
            LinkButton _doubleClickButton = (LinkButton)e.Row.Cells[1].Controls[0];
            // Get the javascript which is assigned to this LinkButton
            string _jsDouble =
            ClientScript.GetPostBackClientHyperlink(_doubleClickButton, "");
            // Add this javascript to the ondblclick Attribute of the row
            e.Row.Attributes["ondblclick"] = _jsDouble;


        }
    }

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // on single click
            e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';";
            e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
            e.Row.ToolTip = "Click to select row";
            e.Row.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
            // on double click
            e.Row.Attributes["ondblclick"] = Page.ClientScript.GetPostBackClientHyperlink(GridView1, "Edit$" + e.Row.RowIndex);
            e.Row.Attributes["style"] = "cursor:pointer";
        }
    }