Solved

How to Copy FROM Excel and Paste TO Gridview

Posted on 2013-01-14
4
1,488 Views
Last Modified: 2013-01-19
I need to copy one row and paste to a gridview, and perform validation thereafter after using the CTRL-V key press. I've seen it done, but do not have access to the code.

Thx!
0
Comment
Question by:devo00
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 30

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 500 total points
ID: 38775805
I can't test this code now but try the following link, hope that's what you need:

http://blogs.msdn.com/b/jebarson/archive/2010/06/29/copy-and-paste-excel-or-clipboard-data-to-gridview-in-asp-net.aspx
0
 

Author Comment

by:devo00
ID: 38775812
Yep I'm using that already, but it does not handle CTRL-V.
0
 

Accepted Solution

by:
devo00 earned 0 total points
ID: 38776023
Figured this out on my own using jQuery for the CTRL-V detection and I had been using the solution above already for GridView population. I use JS to find and push a hidden button to run a back-end C# method (probably a better way to do that, I'll keep looking).

(This is I.E. only, as I understand it, other browsers do not allow clipboard access....)

    <script src="jquery-1.8.3.min.js"></script>
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            $(document).keydown(function (e) {
                if (e.ctrlKey && e.keyCode == 86) {
                    document.getElementById('ClipboardContent').value = window.clipboardData.getData('Text');
                    var btn = document.getElementById("<%=SomeButtonID.ClientID%>");
                    btn.click();
                }
            });
        });
    </script>

    <asp:HiddenField ID="ClipboardContent" runat="server" />
    <asp:ImageButton ID="SomeButtonID" runat="server" ImageUrl="~/images/spacer.gif"
            OnClick="SomeButtonID_Click" />

Open in new window


    protected void SomeButtonID_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(this.ClipboardContent.Value))
        {
            // Use the statement below if you wish to cast to object.
            this.GridView1.DataSource = DataMapper.GetData<TestData>(this.ClipboardContent.Value);
            //this.GridView1.DataSource = DataMapper.GetDataTable(this.ClipboardContent.Value, true);
            this.GridView1.DataBind();
        }
    }

Open in new window

DataMapper.cs
TestData.cs
0
 

Author Closing Comment

by:devo00
ID: 38796083
Found the solution on my own, the contributor found the same resource as I did, so I am giving him the points.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question