title: Excel Export in ASP.NET Web Service
body: <p>I have this ASP.Net Web Application and in one of my Pages I'm using JQuery JQGrid, I want to be able to export the JQGrid to Excel Sheet, so using JavaScript I Collected the Values in an Array and then called a WebService to fill the values in a DataGrid, I successfully done all that, except for the exporting in the WebService no file download appears, and this is my WebService code:</p>
  
  <pre><code>[WebMethod]
  public void GetData(object[] Values)
  {
      DT_ToFill.Columns.Add("CaseID");
      DT_ToFill.Columns.Add("SR");
  
      foreach (object Value in Values)
      {
          Dictionary&lt;string, object&gt; DictVals = new Dictionary&lt;string, object&gt;();
          DictVals = (Dictionary&lt;string, object&gt;)Value;
          string CaseID = DictVals["CaseID"].ToString();
          string SR = DictVals["SR"].ToString();
  
          object[] Obj = new object[2] { CaseID, SR };
          DT_ToFill.Rows.Add(Obj);
      }
      ExportToExcel(DT_ToFill, Context.Response);
  }
  
  [WebMethod]
  public string HelloWorld()
  {
      return "Hello World";
  }
  
  public void ExportToExcel(DataTable dt, HttpResponse Response)
  {
      GridView GridView1 = new GridView();
      GridView1.DataSource = dt;
      Response.Buffer = true;
      Response.AddHeader("Content-Disposition", "inline;filename=Schedule_ExcelSheet.xls");
      Response.Charset = "";
      Response.ContentType = "application/ms-excel";
      Response.Charset = "UTF-8";
      Response.ContentEncoding = Encoding.UTF8;
      StringWriter sw = new StringWriter();
      HtmlTextWriter ht = new HtmlTextWriter(sw);
      GridView1.AllowPaging = false;
      GridView1.DataBind();
      GridView1.RenderControl(ht);
      Response.Output.Write(sw.ToString());
      Response.Flush();
      Response.End();
  }
  
  public void VerifyRenderingInServerForm(Control control)
  {
  }
  </code></pre>
  
  <p>Help Please...
  Thanks</p>