protected void LinkBtnExportExcel_Click(object sender, EventArgs e) { try { System.Threading.Thread.Sleep(2000); Response.Clear(); Response.Buffer = true; Response.ClearContent(); Response.ClearHeaders(); Response.Charset = ""; string FileName = "SaleProductWiseList.xls"; StringWriter strwritter = new StringWriter(); HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName); GV_ProSale.GridLines = GridLines.Both; GV_ProSale.HeaderStyle.Font.Bold = true; GV_ProSale.RenderControl(htmltextwrtter); Response.Write(strwritter.ToString()); Response.End(); } catch (Exception ex) { throw; //ScriptManager.RegisterStartupScript(this, this.GetType(), "isActive", "Alert();", true); //lblalert.Text = ex.Message; } }
private void get_ptroyrsal(string yr, string Proid) { try { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "select * from v_rptSal where ProductID = " + Proid + " and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'" + //cmd.CommandText = "select * from v_rptDSal where ProductID = '" + Proid + // "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "' and [YEAR]='" + YR + "'"; cmd.Connection = con; con.Open(); DataTable dtprosal = new DataTable(); SqlDataAdapter adp = new SqlDataAdapter(cmd); adp.Fill(dtprosal); if (dtprosal.Rows.Count > 0) { lbl_pro.Text = dtprosal.Rows[0]["ProductName"].ToString(); GV_ProSale.DataSource = dtprosal; GV_ProSale.DataBind(); } con.Close(); } } catch (Exception ex) { throw ex; } }