We help IT Professionals succeed at work.
Get Started

SharePoint 2010 Web Part Gridview to CSV

Last Modified: 2015-10-07
I have written an web part that has a gridview on it that I populate and display on assorted web part pages.   All that seems to work fine.  Now I need to capture the gridview data and present it to a user on their clicking a "Load CSV" button on that web part.  

The code follows and indeed works:
   private void ExportGridToCSV()
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=Employee.csv");
            Response.Charset = "";
            Response.ContentType = "application/text";
            GridEmployee.AllowPaging = false;

            StringBuilder columnbind = new StringBuilder();
            for (int k = 0; k < GridEmployee.Columns.Count; k++)

                columnbind.Append(GridEmployee.Columns[k].HeaderText + ',');

            for (int i = 0; i < GridEmployee.Rows.Count; i++)
                for (int k = 0; k < GridEmployee.Columns.Count; k++)

                    columnbind.Append(GridEmployee.Rows[i].Cells[k].Text + ',');



Open in new window

The problem is that once the click event calls this code, the page no longer seems to be connected to the code behind and subsequent clicks don't get handled (I have a breakpoint which is never reached in the beginning of the click events).
Watch Question
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE