// To Get the Defects according to the Login Id ie., User public void CheckDefectReport() { objDefects.EmployeeId = Convert.ToInt32(Session["UserAccountID"]); DataSet dsReport = objDefects.CheckDefectReport(); if (dsReport.Tables[0].Rows.Count > 0) { GVDefectReports.DataSource = dsReport.Tables[0]; GVDefectReports.DataBind(); } }
protected void btnExcelFormat_Click(object sender, EventArgs e) { try { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=DocumentReport.xls"); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.ms-excel"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); GVDefectReports.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } catch (Exception ex) { lblMsg.Visible = true; lblMsg.Text = ex.Message.ToString(); } }