【问题标题】:Copy gridview cell value to the clipboard将 gridview 单元格值复制到剪贴板
【发布时间】:2015-09-27 18:18:33
【问题描述】:

我有一个带有一些值的网格视图。如果用户单击其中一行上的链接或按钮(这里我使用带有文本“复制”的按钮字段),它应该将该行的单元格值复制到剪贴板。 在 asp.net c# 中这样的事情可能吗?

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="id" DataSourceID="SqlDataSource1" Visible="False"  OnRowDataBound="GridView1_RowDataBound"
        onselectedindexchanged="GridView1_SelectedIndexChanged1">
        <Columns>
            <asp:BoundField DataField="Username" HeaderText="Username" 
                SortExpression="Username" />
            <asp:BoundField DataField="Password" HeaderText="Password" 
                SortExpression="Password" />
            <asp:CommandField ButtonType="Image" EditImageUrl="/images/edit.png" CancelImageUrl="/images/undo.png"  UpdateImageUrl="/images/save.png" ShowEditButton="True"   />
            <asp:CommandField ButtonType="Image" ShowDeleteButton="True"  DeleteImageUrl="/images/deletered.png"    />
            <asp:ButtonField Text="Copy"  />
        </Columns>
        <EmptyDataTemplate>
            No data available
        </EmptyDataTemplate>
    </asp:GridView>

ButtonField 没有可用的 Onclick 事件。否则我会考虑使用一些 javascript(我在其他解决方案中看到过)
感谢您的任何意见。

【问题讨论】:

标签: c# asp.net gridview


【解决方案1】:

您只能使用 Windows 窗体来执行此操作,但由于您正在处理 Web 应用程序,因此您应该编写客户端代码,即 javascript,以便在客户端而不是服务器端复制数据。结帐this链接

【讨论】:

  • 您的回答对我来说更像是评论,因为它没有回答 OP 的问题。
  • 目标是获取 e.Row.Cells[1].Text 值并将其分配给“剪贴板”。 asp.net 中的任何实际示例都会非常有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 2019-11-17
相关资源
最近更新 更多