This is a migrated thread and some comments may be shown as answers.

Copy/Paste to Clipboard using radcontextmenu

1 Answer 42 Views
Menu
This is a migrated thread and some comments may be shown as answers.
reguapo
Top achievements
Rank 1
reguapo asked on 12 Aug 2013, 08:21 PM
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??

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 13 Aug 2013, 07:25 AM
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.
Tags
Menu
Asked by
reguapo
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or