[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to Copy FROM Excel and Paste TO Gridview

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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

656 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