protected void ExportExcel() { Response.Clear(); Response.Buffer = true; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("content-disposition", "attachment;filename=" + ddlplanner.SelectedItem.Text.Replace(" ", "_") + "_Activities_" + DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss").Replace("-", "_") + ".xls"); Response.Charset = ""; this.EnableViewState = false; System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw); GridViewLMS_excel.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); }
void FillGridLMS(string plannercode) { if ((string)Session["AdminSessionID"] != null) { string xCode = Session["AdminSessionID"].ToString(); string xSearchRes = ""; string xCB = ""; string xPlannerAssign = ""; string xOperatorAssign = ""; string xCustomer = ""; string xLeadType = ""; if (DDLeadType.SelectedValue.ToString() != "-1") { xLeadType = " and LeadType='" + DDLeadType.SelectedValue + "' "; } xOperatorAssign = " and PlannerCode=" + plannercode + " "; string sr = " " + " select Code, PlannerCode=isnull(PlannerCode,-1), Name, Gender, Age=(year(getdate())-year(DOB)), " + " OperatorCode=isnull(OperatorCode,-1), Mobile1, Email1, City, " + " Source1=isnull((Select Name from fp_ComboDetail where Code=p.Source1 ),'N/A'), " + " Source2=isnull((Select Name from fp_ComboDetail where Code=p.Source2 ),'N/A')," + " Source3=isnull((Select C_Name from fp_Campaign where C_ClientSatusCode=p.ClientStatus ),'N/A')," + " OPType1, OPType2, SiteAC, TxnAC, " + " Remarks,EntryDate=Convert(varchar(11), SystemDate, 105), LeadType=isnull(LeadType,-1), " + " AllocateDate=convert(varchar(11),allocateDate,105)," + " LastActivityDate=isnull((select convert(varchar(11), max(ActionDate), 105) " + " from fp_ActivityMonitor where ClientCode=p.Code),'Create'), PlannerLock=isnull(PLock,'X') " + " from fp_prospects p where Name like '%" + xSearchRes + "%' " + xCB + " " + xPlannerAssign + " " + " " + xOperatorAssign + " " + xCustomer + " " + xLeadType + " order by SystemDate desc " + " "; SqlDataAdapter GDA = new SqlDataAdapter(sr, Con); DataSet GDS = new DataSet(); Con.Open(); GDA.Fill(GDS); Con.Close(); GridViewLMS.DataSource = GDS; GridViewLMS.DataBind(); GridViewLMS_excel.DataSource = GDS; GridViewLMS_excel.DataBind(); } else { Response.Redirect("SessionExpired.aspx"); } }