?
Solved

How to Copy FROM Excel and Paste TO Gridview

Posted on 2013-01-14
4
Medium Priority
?
1,640 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
  • 3
4 Comments
 
LVL 30

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 1500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
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…

568 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