Export Data table into ms Excel file in asp.net

      private void FnExportDataIntoExcel()
                  {
                                       // get data from Database
                                                   dtDataToExport = objDBClass.GetDataFunction(objParam);   // call Data access layer function to get data from Database to export
   
                                                                if (dtDataToExport != null
                       && dtDataToExport.Rows.Count > 0)
                {
                    DataTable dataTable = dtDataToExport;
                    //File Name
                    string DT = DateTime.Now.ToString("yyyyMMdd_hhmmsssstt");
                    // Set up the Response object...
                    this.Response.BufferOutput = false;
                    this.Response.Charset = string.Empty;
                    this.Response.Clear();
                    this.Response.ClearContent();
                    this.Response.ClearHeaders();

                    this.Response.ContentType = "application/vnd.ms-excel";

                    // Open the document OVER this window:
                    string contentDisposition = "attachment; filename=" + "SalesReport_GST" + "_" + DT + ".xls";
                    this.Response.AppendHeader("content-disposition", contentDisposition);

                    // Create a table HTML tag...
                    string textOutput =
                    "<table border='1' bordercolor='black' rules='all' " +
                    "style='BORDER: 1px double; BORDER-COLLAPSE: collapse;'>\r\n";
                    this.Response.Write(textOutput);

                    // Write out the column headers...
                    textOutput = "<tr height=17 style='height:12.75pt'>\r\n";
                    for (int i = 0; i < dataTable.Columns.Count; i++)
                    {
                        textOutput += string.Format(
                        System.Globalization.CultureInfo.InvariantCulture,
                        "<th align='left'>{0}</th>",
                        dataTable.Columns[i].ColumnName);
                    }
                    textOutput += "</tr>\r\n";
                    this.Response.Write(textOutput);


                    // Write out each row of the DataTable...
                    textOutput = string.Empty;
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        System.Data.DataRow dataRow = dataTable.Rows[i];
                        textOutput = "<tr height=17 style='height:12.75pt'>\r\n";

                        // Loop through the columns for each row and grab the values...
                        for (int j = 0; j < dataTable.Columns.Count; j++)
                        {
                            string dataRowText = dataRow[j].ToString().Trim();

                            // Remove any tabs, carriage returns, or newlines from the value...
                            dataRowText = dataRowText.Replace("\t", " ");
                            dataRowText = dataRowText.Replace("\r", string.Empty);
                            dataRowText = dataRowText.Replace("\n", " ");

                            textOutput += string.Format(
                            System.Globalization.CultureInfo.InvariantCulture,
                            "<td align='left' style='mso-number-format:\\@;'>{0}</td>",
                            dataRowText);
                        }

                        textOutput += "</tr>\r\n";
                        this.Response.Write(textOutput);
                    }

                    // Close the HTML table tag... 
                    textOutput = "</table>\r\n";
                    this.Response.Write(textOutput);

                    // Close the Response stream...
                    this.Response.Flush();
                    this.Response.Close();
                    //  this.Response.End();;
                    HttpContext.Current.Response.Flush();
                    HttpContext.Current.Response.SuppressContent = true;
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                }
                else
                {
                                                                               
                                                                                // call your function to show message like this
                     string  msg = "No Records Found to export";
                    // bgcolor = "red";
                    //DisplayMessage(msg, bgcolor);
                }
                                }