<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation ="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function clipper() {
var data = document.getElementById("Label1").href;
alert("Clipboard = \n\n" + data);
window.clipboardData.setData("Text", data);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="divGridView">
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" AutoGenerateColumns="False" Width="251px"
onrowdatabound="GridView1_RowDataBound">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:clipper()"><asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
<div>
</div>
</form>
</body>
</html>
===========================================================
this is code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
DataTable myTable;
protected void Page_Load(object sender, EventArgs e)
{
myTable = new DataTable();
myTable.Columns.Add("ID", typeof(Int32));
myTable.Columns.Add("Name", typeof(String));
myTable.Rows.Add(1, "aaa");
myTable.Rows.Add(2, "bbb");
myTable.Rows.Add(3, "ccc");
GridView1.DataSource = myTable;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//if (e.Row.RowType == DataControlRowType.DataRow)
//{
// Label lbl = e.Row.FindControl("Label2") as Label;
// Button btn = e.Row.FindControl("Button2") as Button;
// btn.Attributes.Add("onclick", "return CopyGridView('" + lbl.ClientID + "')");
//}
}
}
http://www.dynamic-tools.net/toolbox/copyToClipboard/