ib bellad

ib bellad

  • 1.3k
  • 376
  • 33.7k

export data from gridview to msword

Jul 31 2014 4:29 AM
HI 
  Frnd's.., I had try below showing code to convert data from gridview to msword..but the end data is saved in notepad  i need to save in msword..can any1 help..


protected void btn_export_Click(object sender, EventArgs e)
{

GridView1.AllowPaging = false;
        GridView1.DataBind();
        Response.ClearContent();


        Response.AddHeader("content-disposition", string.Format("attachment;filename{0}", "customer.doc"));
        
         Response.Charset = "";
        Response.ContentType = "application/ms-word";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        GridView1.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();
        lab_msg.Text = "data saved";
        lab_msg.ForeColor = Color.Green;
    }
                        thank you..


Answers (3)