Solved

How to Copy FROM Excel and Paste TO Gridview

Posted on 2013-01-14
4
1,386 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 29

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Log4Net custom Appender not being fired. 5 41
Windows Service to Receive TCP Packets 4 33
String manipulation 15 49
Create XML 5 31
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now