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
|