View Single Post
  #2 (permalink)  
Old 03-21-2007, 06:36 AM
leodeveloper leodeveloper is offline
WMG Newcomer
 
Join Date: Mar 2007
Posts: 10
iTrader: (0)
leodeveloper is on a distinguished road
Default Export data from datagride to excel

yes the following code wil helps you

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

//Bind the DataGrid to DataSet

DataGridToExcel (DataGrid1, Response);

}

protected void DataGridToExcel(DataGrid dGridExport , HttpResponse httpResp)

{

httpResp.Clear();

httpResp.Charset = "";

httpResp.ContentType = "application/vnd.ms-excel";

StringWriter stringWrite = new StringWriter();

HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

DataGrid dGrid = new DataGrid();

dGrid = dGridExport;

dGrid.HeaderStyle.Font.Bold = true;

dGrid.DataBind();

dGrid.RenderControl(htmlWrite);

httpResp.Write(stringWrite.ToString());

httpResp.End();

}


Allah Bless on you
Reply With Quote
Sponsored Links
Register and sign in to hide this ad block