AMOL

AMOL

  • NA
  • 17
  • 14k

I want to save the contents of gridview to the excel file and i am using the following code to done ...

Aug 27 2012 12:55 AM
 protected void SaveBtn_Click(object sender, EventArgs e)
    {
        try
        {
            System.IO.StringWriter sw = new System.IO.StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            Response.AddHeader("content-disposition", "attachment; filename=" + DropDownList1.SelectedItem.Text + "_" + DropDownList2.SelectedItem.Text + "_" + DropDownList3.SelectedItem.Text + "_" + TextBox1.Text + ".xls");
            Response.ClearContent();
            GridView1.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.Flush();
            Response.End();
 
        }
        catch (Exception ex)
        {

        }
    }
    public override void VerifyRenderingInServerForm(Control control)
    {

        /* Verifies that the control is rendered */

    }

Answers (1)