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

  • Home
  • SEARCH
  • 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 8180671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:15:46+00:00 2026-06-07T00:15:46+00:00

From my website, I have a button which calls a method and then generates

  • 0

From my website, I have a button which calls a method and then generates reports to excel. the code works. The problem is that the code displays all gridviews (there are 3) on the same tab. What code may I add to this so that when i click on the button, it will download the document but have each gridview displayed on their separate tabs. The tab names will be top 1, top 2, and top 3. So to clarify, right now all of the gridviews are displayed on the top 1 tab, I need to make 2 more tabs (top 2 and top 3) and put gridview2 on top 2 tab, and gridview3 on the top 3 tab.

using System;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Text;
using System.IO;



public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
    DataSet dataSet = new DataSet();

    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ISALog1ConnectionString"].ToString());

    SqlCommand cmd = new SqlCommand("exec ProxyReport", conn);
    cmd.CommandTimeout = 200;

    SqlDataAdapter ad = new SqlDataAdapter(cmd);
    ad.Fill(dataSet);

    GridView1.DataSource = dataSet.Tables[0];
    GridView1.DataBind();
    GridView2.DataSource = dataSet.Tables[1];
    GridView2.DataBind();
    GridView3.DataSource = dataSet.Tables[2];
    GridView3.DataBind();

}
protected void Button1_Click(object sender, EventArgs e)
{
    string attachment = "attachment; filename=Top 1.xls";
    Response.ClearContent();
    Response.AddHeader("content-disposition", attachment);
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ContentType = "application/ms-excel";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    GridView1.RenderControl(htw);
    GridView2.RenderControl(htw);
    GridView3.RenderControl(htw);
    Response.Write(sw.ToString());
    Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{

}


}
  • 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-06-07T00:15:47+00:00Added an answer on June 7, 2026 at 12:15 am

    Yes, you need to add EPPlus from codeplex: http://epplus.codeplex.com/ and then add this to your code. You can use it to add as many worksheets as you want:

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Web;
        using System.Web.UI;
        using System.Web.UI.WebControls;
        using System.Data;
        using System.Data.SqlClient;
        using System.IO;
        using OfficeOpenXml;
        using System.Configuration;
    
        public partial class _Default : System.Web.UI.Page
        {
    protected void Page_Load(object sender, EventArgs e)
    {
    
    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        GetExcel ge = new GetExcel();
        ge.ProcessRequest(HttpContext.Current);
    }
    
    public class GetExcel : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            DataSet dataSet = new DataSet();
    
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ISALog1ConnectionString"].ToString());
            SqlCommand cmd = new SqlCommand("exec ProxyReport", conn);
            cmd.CommandTimeout = 200;
            SqlDataAdapter ad = new SqlDataAdapter(cmd);
            ad.Fill(dataSet);
    
           GridView1.DataSource = dataSet.Tables[0];
           GridView1.DataBind();
           GridView2.DataSource = dataSet.Tables[1];
           GridView2.DataBind();
           GridView3.DataSource = dataSet.Tables[2];
           GridView3.DataBind();   
    
            dataSet.Tables[0].TableName = "1";
            dataSet.Tables[1].TableName = "2";
            dataSet.Tables[2].TableName = "3";
    
            int count = 3;   
    
                MemoryStream ms = GetExcel.DataTableToExcelXlsx(dataSet, count);
                ms.WriteTo(context.Response.OutputStream);
                context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                context.Response.AddHeader("Content-Disposition", "attachment;filename=EPPlusData.xlsx");
                context.Response.StatusCode = 200;
                context.Response.End();
    
        }
    
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    
        public static MemoryStream DataTableToExcelXlsx(DataSet ds, int count)
        {
            MemoryStream Result = new MemoryStream();
            ExcelPackage pack = new ExcelPackage();
    
            for (int i = 1; i <= count; i++)
            {
                DataTable table = ds.Tables[i.ToString()];
                ExcelWorksheet ws = pack.Workbook.Worksheets.Add("MySheet" + i.ToString());
    
                int col = 1;
                int row = 1;
    
                foreach (DataColumn cl in table.Columns)
                {
                    ws.Cells[row, col].Value = cl.ColumnName;
                    col++;
                }
                col = 1;
                foreach (DataRow rw in table.Rows)
                {
                    foreach (DataColumn cl in table.Columns)
                    {
                        if (rw[cl.ColumnName] != DBNull.Value)
                            ws.Cells[row + 1, col].Value = rw[cl.ColumnName].ToString();
                        col++;
                    }
                    row++;
                    col = 1;
                }
            }
            pack.SaveAs(Result);
            return Result;
        }
    }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem I have some pages that need dynamic data from website to generate output
Suppose we have a website in which you click on a button, and that
I have python script which downloads N number of images from website. I run
I have a website (ASP.NET MVC3) that runs on IIS 7. From this website,
I am getting JSON string from website. I have data which looks like this
I have a link on my website which opens a html content from a
I have a website that grabs a random entry from a database and displays
I want to parse a couple of thousands XML-files from a website(I have permission)
We have a website wherein a user can post information from our website to
I am downloading a file from a website and I have the link. But

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.