Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i have two grid view with different header and data.I want to display it in same excel with different sheet.I am able to display one grid view.how to extent it for multiple grid views.

What I have tried:

C#
Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment;filename=Industrialzonestatus.xls");
                Response.Charset = "";
                Response.ContentType = "application/vnd.ms-excel";
                using (StringWriter sw = new StringWriter())
                {
                    HtmlTextWriter hw = new HtmlTextWriter(sw);

                    //To Export all pages
                    GridView GridView1 = new GridView();
                    GridView1.AllowPaging = false;
                    GridView1.DataSource = dt;
                    GridView1.DataBind();

                    GridView1.HeaderRow.BackColor = Color.White;
                    foreach (TableCell cell in GridView1.HeaderRow.Cells)
                    {
                        cell.BackColor = GridView1.HeaderStyle.BackColor;
                    }

                    if (GridView1.Rows.Count > 0)
                    {
                        GridView1.HeaderRow.Cells[0].Text = "Industrial Zone";
                        GridView1.HeaderRow.Cells[1].Text = "District";
                          GridView1.HeaderRow.Cells[2].Text = "Taluk";
                          GridView1.HeaderRow.Cells[3].Text = "Contact Title";
                          GridView1.HeaderRow.Cells[4].Text = "Industrial Area";
                          GridView1.HeaderRow.Cells[5].Text = "Plot Number";
                          GridView1.HeaderRow.Cells[6].Text = "Plot Area";
                          GridView1.HeaderRow.Cells[7].Text = "Name of Allottee";
                          GridView1.HeaderRow.Cells[8].Text = "Address of Allottee";
                          GridView1.HeaderRow.Cells[9].Text = "Nature of Industry";
                          GridView1.HeaderRow.Cells[10].Text = "Reservation";
                          GridView1.HeaderRow.Cells[11].Text = "Index";
                          GridView1.HeaderRow.Cells[12].Text = "Plot Status";
                          GridView1.HeaderRow.Cells[13].Text = "Implimentation Status";
                          GridView1.HeaderRow.Cells[14].Text = "Date of Possession";
                          GridView1.HeaderRow.Cells[15].Text = "Date of Allotment";
                          GridView1.HeaderRow.Cells[16].Text = "Due Date of Payment";
                          GridView1.HeaderRow.Cells[17].Text = "Date of Lease Agreement Executed";
                         GridView1.HeaderRow.Cells[18].Text = "Stipulated time for commencement of production";
                         GridView1.HeaderRow.Cells[19].Text = "Extension of time Granted";
                         GridView1.HeaderRow.Cells[20].Text = "Remarks";
                         GridView1.HeaderRow.Cells[21].Text = "Plot Updated Date";
                    }
                    foreach (GridViewRow row in GridView1.Rows)
                    {
                        row.BackColor = Color.White;
                        foreach (TableCell cell in row.Cells)
                        {
                            if (row.RowIndex % 2 == 0)
                            {
                                cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
                            }
                            else
                            {
                                cell.BackColor = GridView1.RowStyle.BackColor;
                            }
                            cell.CssClass = "textmode";
                        }
                    }

                    GridView1.RenderControl(hw);

                    //style to format numbers to string
                    string style = @"<style> .textmode { } </style>";
                    Response.Write(style);
                    Response.Output.Write(sw.ToString());
                    Response.Flush();
                    Response.End();
                }
Posted
Updated 14-Jun-16 21:36pm
v2
Comments
Herman<T>.Instance 15-Jun-16 3:36am    
Try using EPPLUS or something like that. It will make it more easier for you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900