1
Answer

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

AMOL

AMOL

12y
1.9k
1
 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)