?
Solved

How to Copy FROM Excel and Paste TO Gridview

Posted on 2013-01-14
4
Medium Priority
?
1,525 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 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Suggested Courses

770 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