protected void BindTeam() { try { using (sqlCon) { using (SqlCommand sqlCmd = new SqlCommand("Search", sqlCon)) { sqlCon.Open(); DataTable dt = new DataTable(); sqlCmd.CommandType = System.Data.CommandType.StoredProcedure; Matchdetail.DataSource = sqlCmd.ExecuteReader(); Matchdetail.DataBind(); if (Matchdetail.Rows.Count == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' No record found')", true); } sqlCon.Close(); } } } catch (Exception ex) { Response.Write("Error:" + ex.Message.ToString()); } }
private void ExportGridToExcel() { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); Matchdetail.AllowPaging = false; Matchdetail.DataBind(); Matchdetail.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); }