Friday, June 24, 2011

Export to word from gridview in c#

protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{

Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Individual report of user" + " " + ddlagent.SelectedItem.Text + ".doc"));
Response.ContentType = "application/ms-word";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
getgrid();
//Change the Header Row back to white color
//Applying stlye to gridview header cells
DataList1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();


}

No comments:

Post a Comment