Copy/Paste to Clipboard using radcontextmenu

2 posts, 0 answers
  1. reguapo
    reguapo avatar
    16 posts
    Member since:
    Jul 2009

    Posted 12 Aug 2013 Link to this post

    I have a radlistbox, and I want to let the user select multiple items and right click and then copy, and let the user use that copied item into for example Microsoft Word, Notepad, etc ... How can I accomplish this??
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Aug 2013 Link to this post

    Hi reguapo,

    Please have a look into the following code I tried which works fine at my end.

    ASPX:
    <telerik:RadListBox ID="RadListBox1" runat="server" SelectionMode="Multiple">
        <Items>
            <telerik:RadListBoxItem runat="server" Text="Item 1" />
            <telerik:RadListBoxItem runat="server" Text="Item 2" />
            <telerik:RadListBoxItem runat="server" Text="Item 3" />
        </Items>
    </telerik:RadListBox>
    <telerik:RadContextMenu ID="RadContextMenu1" runat="server" OnClientItemClicked="OnClientItemClicked">
        <Targets>
            <telerik:ContextMenuControlTarget ControlID="RadListBox1" />
        </Targets>
        <Items>
            <telerik:RadMenuItem runat="server" Text="Copy">
            </telerik:RadMenuItem>
        </Items>
    </telerik:RadContextMenu>
     

    JavaScript:
    <script type="text/javascript">
        function OnClientItemClicked(sender, args) {
            if (args.get_item().get_text() == "Copy") {
                var radlistbox = $find('<%=RadListBox1.ClientID %>');
                var selecteditems = radlistbox.get_selectedItems();
                var itemname = "";
                for (var counter = 0; counter < selecteditems.length; counter++) {
                    itemname += selecteditems[counter].get_text() + " ";
                }
                if (window.clipboardData && clipboardData.setData) {
                    clipboardData.setData("Text", itemname.toString());
                }
            }
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top