You must Sign In to post a response.
  • Category: ASP.NET

    Copy gridview to clipboard

    I am trying to copy gridview to clipboard.So I refered following link. How to Copy copy ASP.NET GridView to clipboard . When I am using this code 'PRTL_UtilityPackage' is not visible to me. Do u have any idea about it? So I decided to use javascript code.

    <script type="text/javascript">
    function CopyGridView() {
    var div = document.getElementById('divGridView');
    div.contentEditable = 'true';
    var controlRange;
    if (document.body.createControlRange) {
    controlRange = document.body.createControlRange();
    controlRange.addElement(div);
    controlRange.execCommand('Copy');
    }
    div.contentEditable = 'false';
    }
    </script>
    It is working fine,but problem is that if gridview have paging,it shows only first page data not all pages data.If number is big,when pasting data in excel,it is showing +some part of number.I want to show entire number.How to handle this?
  • #764780
    The code which you are using is correct.

    function CopyGridView()
    {
    var div = document.getElementById("ctl00_MainContent_GVStudentList");
    div.contentEditable = 'true';
    var controlRange;
    if (document.body.createControlRange)
    {
    controlRange = document.body.createControlRange();
    controlRange.addElement(div);
    controlRange.execCommand('Copy');
    }
    div.contentEditable = 'false';
    }


    Copping to clip board is copping from the page to clip board. It will not take the gridview paging. If it has lot of records, that time it will copy but now its based on your buffer, so that is depend on the memory.

    In this case you can close all other memory conception programs then try to copy that.

    By Nathan
    Direction is important than speed

  • #764798
    Hi,
    As you know copy always works with the data you are able to see. Especially while using JavaScript it cannot read the data which is not in the browser.

    Otherwise you may have to disable the paging while copying the data and have to copy to clipboard.


    Regards,
    Asheej T K
    Microsoft MVP[ASP.NET/IIS]
    DotNetSpider MVM

  • #764829
    Hai Pinky,
    If there is no issue with the code and it working fine. The issue you have mentioned is related to the page number so this could be the UI related issue which can be checked in the Browser. Go to your browser, press F12 key, you will see a small window below, click on the arrow at the top left of the window and then click on the place where the page numbers are displayed, see there could be some style which is causing the issue.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764838
    Hi pinky,
    Try this:
    var copyText = document.getElementById('gvDemo').innerText;
    window.clipboardData.setData("Text", copyText);
    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com


Sign In to post your comments