GridView RowCommand将e.CommandArgument值复制到剪贴板

时间:2016-08-30 13:18:18

标签: vba gridview copy clipboard rowcommand

Protected Sub GridView_Paga_AT_0_RowCommand(sender As Object, e As GridViewCommandEventArgs)

    If e.CommandName = "C_Nif" Then

        Dim row As GridViewRow = DirectCast(DirectCast(e.CommandSource, Control).NamingContainer, GridViewRow)
        Dim Botao_Nif As ImageButton = TryCast(row.FindControl("ImageButton_C_Nif"), ImageButton)
        Dim Nif As String = e.CommandArgument
        Botao_Nif.Attributes.Add("onclick", "function copyClipboard(){window.clipboardData.setData('Text'," + Nif + ");CopiedTxt.execCommand('Copy');}")

    End If

End Sub

1 个答案:

答案 0 :(得分:0)

经过一番搜索后,对我来说最好的解决方案是:

    If e.CommandName = "C_Nif" Then

        Dim row As GridViewRow = DirectCast(DirectCast(e.CommandSource, Control).NamingContainer, GridViewRow)
        Dim Botao_Nif As ImageButton = TryCast(row.FindControl("ImageButton_C_Nif"), ImageButton)

        Dim Nif As String = e.CommandArgument
        Botao_Nif.Attributes.Add("onclick", "window.prompt(""To copy use Ctrl+C. Close with Enter.""," + Nif + ");")

    End If