Advertisements

Convert Gried view to excel in Asp.net



 

//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
//eg=

grid view start here

protected void btn_export_Click(object sender, EventArgs e)
{

Response.Clear();
Response.AddHeader(“content-disposition”, “attachment;filename=FileName.xls”);
Response.Charset = “”;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
//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);
divexport.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}

public override void VerifyRenderingInServerForm(Control control)
{

/* Verifies that the control is rendered */
}

 


Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: