Click here to Skip to main content
15,887,434 members
Home / Discussions / ASP.NET
   

ASP.NET

 
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?
QuestionCustomize the WebApi2 Authentication and Authorization + Oauth Pin
Member 103245156-Mar-14 20:41
Member 103245156-Mar-14 20:41 
QuestionBlog Pin
dotnetpls6-Mar-14 7:53
dotnetpls6-Mar-14 7:53 
AnswerRe: Blog Pin
Richard Deeming6-Mar-14 8:08
mveRichard Deeming6-Mar-14 8:08 
GeneralRe: Blog Pin
dotnetpls6-Mar-14 8:59
dotnetpls6-Mar-14 8:59 
GeneralRe: Blog Pin
Richard Deeming6-Mar-14 9:46
mveRichard Deeming6-Mar-14 9:46 
Questiongateway Pin
punith Kumar Raj6-Mar-14 3:19
punith Kumar Raj6-Mar-14 3:19 
SuggestionRe: gateway Pin
Richard Deeming6-Mar-14 3:39
mveRichard Deeming6-Mar-14 3:39 
QuestionMVC4 Razor @model - what's equivalent in ASPX view engine? Pin
Swab.Jat6-Mar-14 0:06
Swab.Jat6-Mar-14 0:06 
AnswerRe: MVC4 Razor @model - what's equivalent in ASPX view engine? Pin
thatraja6-Mar-14 1:57
professionalthatraja6-Mar-14 1:57 
GeneralRe: MVC4 Razor @model - what's equivalent in ASPX view engine? Pin
Swab.Jat6-Mar-14 2:44
Swab.Jat6-Mar-14 2:44 
GeneralRe: MVC4 Razor @model - what's equivalent in ASPX view engine? Pin
thatraja6-Mar-14 3:29
professionalthatraja6-Mar-14 3:29 
GeneralRe: MVC4 Razor @model - what's equivalent in ASPX view engine? Pin
Swab.Jat6-Mar-14 3:36
Swab.Jat6-Mar-14 3:36 
Questionaccess data from another table Pin
Patel Vinay V5-Mar-14 23:54
Patel Vinay V5-Mar-14 23:54 
QuestionEncryption (Clent Side using JS) and Decryption (Server Side) Pin
NICE TO MEET5-Mar-14 21:00
NICE TO MEET5-Mar-14 21:00 
AnswerRe: Encryption (Clent Side using JS) and Decryption (Server Side) Pin
Wayne Gaylard5-Mar-14 21:16
professionalWayne Gaylard5-Mar-14 21:16 
SuggestionRe: Encryption (Clent Side using JS) and Decryption (Server Side) Pin
Richard Deeming6-Mar-14 2:02
mveRichard Deeming6-Mar-14 2:02 
QuestionASP.NET MVC4 MembershipProvider Pin
Swab.Jat5-Mar-14 11:49
Swab.Jat5-Mar-14 11:49 

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.