protected void BtnDownLoad_Click(object sender, EventArgs e) { GvExcel.Visible = true; Context.Response.ClearContent(); Context.Response.ContentType = "application/ms-excel"; Context.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", "AI_SC_List")); Context.Response.Charset = ""; System.IO.StringWriter stringwriter = new System.IO.StringWriter(); HtmlTextWriter htmlwriter = new HtmlTextWriter(stringwriter); GvExcel.RenderControl(htmlwriter); Context.Response.Write(stringwriter.ToString()); Context.Response.End(); }
protected void btnExportToExcel_Click(object sender, EventArgs e) { Response.ClearContent(); Response.AddHeader("Content-Disposition", "attachment;filename=SpareIndent.xls"); Response.ContentType = "application/ms-excel"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); DataSet dsExport = new DataSet(); objSIMSindent.Region_Sno = Convert.ToInt32(ddlRegion.SelectedValue); objSIMSindent.Branch_SNo = Convert.ToInt32(ddlBranch.SelectedValue); objSIMSindent.ASC_Id = Convert.ToInt32(ddlASC.SelectedValue); objSIMSindent.ProductDivision_Id = Convert.ToInt32(ddlProductDivison.SelectedValue); objSIMSindent.From_Date = Convert.ToString(txtFromDate.Text.Trim()); objSIMSindent.To_Date = Convert.ToString(txtToDate.Text.Trim()); dsExport = objSIMSindent.BindData(GvExcel); GvExcel.DataSource = dsExport; GvExcel.DataBind(); GvExcel.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); }
protected void btnExportToExcel_Click(object sender, EventArgs e) { Response.ClearContent(); Response.AddHeader("Content-Disposition", "attachment;filename=SpareRpt.xls"); Response.ContentType = "application/ms-excel"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); DataSet dsExport = new DataSet(); sqlParamSrh[1].Value = ddlSearch.SelectedValue.ToString(); sqlParamSrh[2].Value = txtSearch.Text.Trim(); sqlParamSrh[3].Value = rdoboth.SelectedValue.ToString(); sqlParamSrh[4].Value = User.Identity.Name; sqlParamSrh[5].Value = Convert.ToInt32(DDlProdDiv.SelectedValue); dsExport = objCommonClass.BindDataGrid(GvExcel, "uspSpareMaster", true, sqlParamSrh, true); GvExcel.DataSource = dsExport; GvExcel.DataBind(); GvExcel.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); }