I have created a grid-view with bound data and then I created a simple java script method to copy the whole grid-view on the clipboard, problem is this java script is only working on IE and not on chrome. JS:
<script type="text/javascript">
function CopyGridView() {
var div = document.getElementById('TestCopy').contentEditable = true;
var controlRange;
if (document.body.createControlRange) {
controlRange = document.body.createControlRange();
controlRange.addElement(div);
controlRange.execCommand('Copy');
}
div.contentEditable = 'false';
}
</script>
Gridview:
<div runat="server" id="gvTaskTableDiv" style="width: auto; height: 300px; overflow: auto; background-color: white">
<div id="TestCopy">
<asp:GridView ID="gvTaskTable" runat="server" AutoGenerateColumns="false" CssClass="table table-striped table-actions gridview col-lg-3 col-md-3 col-sm-3 col-xs-12 center-block">
<Columns>
<asp:BoundField HeaderText="Name" DataField="Name" ItemStyle-ForeColor="Black" />
<asp:BoundField HeaderText="Task Description" DataField="TaskDescription" ItemStyle-ForeColor="Black" />
<asp:BoundField HeaderText="Task Status" DataField="TaskStatus" ItemStyle-ForeColor="Black" />
<asp:BoundField HeaderText="Note" DataField="Note" ItemStyle-ForeColor="Black" />
</Columns>
</asp:GridView>
<input id="btnCopyTable" onclick="CopyGridView()" style="position: static" type="button" value="Copy Table" />
</div>
</div>
</div>