Click here to Skip to main content
15,920,632 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: asp.net related question Pin
Tom Marvolo Riddle10-Mar-14 23:36
professionalTom Marvolo Riddle10-Mar-14 23:36 
QuestionSingle Login page for multiple applications. Pin
HemadriT10-Mar-14 10:21
HemadriT10-Mar-14 10:21 
AnswerRe: Single Login page for multiple applications. Pin
RaghuPT11-Mar-14 1:55
RaghuPT11-Mar-14 1:55 
GeneralRe: Single Login page for multiple applications. Pin
HemadriT11-Mar-14 3:52
HemadriT11-Mar-14 3:52 
GeneralRe: Single Login page for multiple applications. Pin
HemadriT11-Mar-14 3:58
HemadriT11-Mar-14 3:58 
AnswerRe: Single Login page for multiple applications. Pin
ZurdoDev11-Mar-14 9:51
professionalZurdoDev11-Mar-14 9:51 
GeneralRe: Single Login page for multiple applications. Pin
HemadriT11-Mar-14 10:19
HemadriT11-Mar-14 10:19 
QuestionRe: Single Login page for multiple applications. Pin
ZurdoDev11-Mar-14 10:20
professionalZurdoDev11-Mar-14 10:20 
Questionhow to add datepicker in gridview boundfield column Pin
heena rohra9-Mar-14 22:48
heena rohra9-Mar-14 22:48 
AnswerRe: how to add datepicker in gridview boundfield column Pin
i gr810-Mar-14 0:06
i gr810-Mar-14 0:06 
AnswerRe: how to add datepicker in gridview boundfield column Pin
Jαved10-Mar-14 22:32
professionalJαved10-Mar-14 22:32 
QuestionUrgent help how creating forums with ASP.NET using C# Pin
Samer Wolf9-Mar-14 2:27
Samer Wolf9-Mar-14 2:27 
AnswerRe: Urgent help how creating forums with ASP.NET using C# Pin
Kornfeld Eliyahu Peter9-Mar-14 2:43
professionalKornfeld Eliyahu Peter9-Mar-14 2:43 
AnswerRe: Urgent help how creating forums with ASP.NET using C# Pin
ZurdoDev11-Mar-14 9:52
professionalZurdoDev11-Mar-14 9:52 
QuestionUsing CrystalReport Implement Print Pin
Mr.Roking8-Mar-14 23:13
Mr.Roking8-Mar-14 23:13 
QuestionWhy it is so hard to play with html in visual studio Pin
ankur11638-Mar-14 18:42
ankur11638-Mar-14 18:42 
AnswerRe: Why it is so hard to play with html in visual studio Pin
ankur11638-Mar-14 20:01
ankur11638-Mar-14 20:01 
SuggestionRe: Why it is so hard to play with html in visual studio Pin
Richard MacCutchan8-Mar-14 22:28
mveRichard MacCutchan8-Mar-14 22:28 
AnswerRe: Why it is so hard to play with html in visual studio Pin
Kornfeld Eliyahu Peter8-Mar-14 23:32
professionalKornfeld Eliyahu Peter8-Mar-14 23:32 
AnswerRe: Why it is so hard to play with html in visual studio Pin
jkirkerx10-Mar-14 13:55
professionaljkirkerx10-Mar-14 13:55 
Questionasp.net site taking all the CPU after a while Pin
Amaranth137-Mar-14 8:02
Amaranth137-Mar-14 8:02 
AnswerRe: asp.net site taking all the CPU after a while Pin
jkirkerx10-Mar-14 14:01
professionaljkirkerx10-Mar-14 14:01 
GeneralRe: asp.net site taking all the CPU after a while Pin
Amaranth1311-Mar-14 4:33
Amaranth1311-Mar-14 4:33 
GeneralRe: asp.net site taking all the CPU after a while Pin
jkirkerx11-Mar-14 7:10
professionaljkirkerx11-Mar-14 7:10 
QuestionSet label for gridview while export to excel Pin
vignesht507-Mar-14 7:52
vignesht507-Mar-14 7:52 
Below is my aspx

<%@ Page Title="Report" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Report.aspx.cs" Inherits="Code" EnableEventValidation="false" %>

<asp:content id="Content1" contentplaceholderid="head" runat="Server">

<asp:label id="Label1" runat="server" font-bold="True" font-size="Medium" font-underline="True"
="" forecolor="#000066" text="Reports">




<asp:gridview id="GridView1" runat="server" showfooter="true" onrowdatabound="GridView1_RowDataBound"
="" width="985px" allowsorting="false" gridlines="None">
<footerstyle horizontalalign="Left" verticalalign="Middle">
<headerstyle font-bold="True" font-names="Times New Roman" font-size="Medium" font-underline="True"
="" forecolor="Blue">
<pagerstyle horizontalalign="Left" verticalalign="Top">
<rowstyle horizontalalign="Left" verticalalign="Middle">






<asp:gridview id="GridView2" runat="server" showfooter="true" allowsorting="false"
="" onrowdatabound="GridView1_RowDataBound" width="985px" gridlines="None" style="margin-left: -315px">
<footerstyle horizontalalign="Left" verticalalign="Middle">
<headerstyle font-bold="True" font-names="Times New Roman" font-size="Medium" font-underline="True"
="" forecolor="Blue">
<pagerstyle horizontalalign="Left" verticalalign="Middle">
<rowstyle horizontalalign="Left" verticalalign="Middle">



I am using the below code to export two gridviews to excel.

protected void ExporttoExcel(object sender, EventArgs e)
{
try
{
GridView[] gvList = null;
gvList = new GridView[] { GridView1, GridView2 };
ExportAv("Report.xls", gvList);
}
catch (Exception ex)
{

}
}

public static void ExportAv(string fileName, GridView[] gvs)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", fileName));
HttpContext.Current.Response.ContentType = "application/ms-excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);

foreach (GridView gv in gvs)
{
gv.AllowPaging = false;

// Create a form to contain the grid
Table table = new Table();

table.GridLines = gv.GridLines;
// add the header row to the table
if (!(gv.Caption == null))
{
TableCell cell = new TableCell();
cell.Text = gv.Caption;
cell.ColumnSpan = 10;
TableRow tr = new TableRow();
tr.Controls.Add(cell);
table.Rows.Add(tr);
}

if (!(gv.HeaderRow == null))
{
table.Rows.Add(gv.HeaderRow);
}
// add each of the data rows to the table
foreach (GridViewRow row in gv.Rows)
{
table.Rows.Add(row);
}
// add the footer row to the table
if (!(gv.FooterRow == null))
{
table.Rows.Add(gv.FooterRow);
}
// render the table into the htmlwriter
table.RenderControl(htw);
}
// render the htmlwriter into the response

string headerTable = @"

Report

" + DateTime.Now.ToString("d") + "

";
HttpContext.Current.Response.Write(headerTable);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
}
This code gives a general title called Report and date at the top of the report. Now how can I possibly give a title name for gridviews when exporting the grid to excel?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.