Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3491240
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:36:47+00:00 2026-05-18T11:36:47+00:00

i built a patient management software for a clinic and i need to export

  • 0

i built a patient management software for a clinic and i need to export patiet list from ASP.net grid view to excel file

my question is:

Is there a way to export gridview to excel
i am using vb.net and visual web developer 2010

i store datasource from advanced search page into a session and redirect to result page
here is the code of result page

Partial Class Sresults
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    GridView1.DataSource = Session("dsource")
    GridView1.DataBind()

End Sub

Protected Sub Backbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Backbtn.Click
    Session("dsource") = ""
    Response.Redirect("searchme.aspx")

End Sub

Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete
    Response.Write(GridView1.Rows.Count.ToString + " Records")
End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:36:48+00:00Added an answer on May 18, 2026 at 11:36 am

    try below code on the button click

    // Get DataTable that DataGrid is bound to.
    var dataTable = (DataTable)dataGrid.DataSource;
    
    // Create new ExcelFile.
    var ef = new ExcelFile();
    // Add new worksheet to the file.
    var ws = ef.Worksheets.Add(dataTable.TableName);
    // Insert the data from DataTable to the worksheet starting at cell "A1".
    ws.InsertDataTable(dataTable, "A1", true);
    
    // Stream file to browser.
    Response.Clear();
    Response.ContentType = "application/vnd.ms-excel";
    Response.AddHeader("Content-Disposition", "attachment; filename=Employee.xls");
    ef.SaveXls(Response.OutputStream);
    Response.End();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I built a site in asp.net C#. Visual Studio 2010. The site scales nicely
I built an application which displays the records from database in the window and
The built-in Math.Pow() function in .NET raises a double base to a double exponent
I have a web app built in coldfusion that receives medical referral letters from
Now that I have built a database. Visual Studio 2008 SP1’s ADO.NET Entity Framework
I built a application, it generates Excel with COM Interop. It works fine on
I built my Django homepage's view using direct_to_template plus lots of extra_context, code example:
I built a web application that inserts value to an excel file and deployed
I'm parsing a list of patient visits (csv file). To deal with this, I
Any built in way to get virtual / relative path or URL from absolute

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.