Convert Gried view to excel in


//set Enable validation = false

<%@ Page Title=”” Language=”C#” MasterPageFile=”~/CAS/CASMasterPage.master”

AutoEventWireup=”true” CodeFile=”Add-Album.aspx.cs” Inherits=”Pages_Add_Album”

EnableEventValidation=”false” %>

// use this below code for download and convert gridvalues into excel
//divexport set id name above gridview

grid view start here

protected void btn_export_Click(object sender, EventArgs e)

Response.AddHeader(“content-disposition”, “attachment;filename=FileName.xls”);
Response.Charset = “”;
//adding style in grid view..
gv_AlbumResult.HeaderRow.Style.Add(“width”, “15%”);
gv_AlbumResult.HeaderRow.Style.Add(“font-size”, “10px”);
gv_AlbumResult.Style.Add(“text-decoration”, “none”);
gv_AlbumResult.Style.Add(“font-family”, “Arial, Helvetica, sans-serif;”);
gv_AlbumResult.Style.Add(“font-size”, “15px”);
//format type assigning..
Response.ContentType = “application/vnd.xls”;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

public override void VerifyRenderingInServerForm(Control control)

/* Verifies that the control is rendered */



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: