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 = "SaleMonthWiseList.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_Month.GridLines = GridLines.Both; GV_Month.HeaderStyle.Font.Bold = true; GV_Month.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_monsal(string Monid, string year) { try { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "select * from v_rptSal where [Month] = '" + Monid + "' and YEAR(Saldat)= '" + year + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'"; //cmd.CommandText = "select * from v_rptDSal where [Month] = '" + Monid + "' and [YEAR]= '" + year + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'"; cmd.Connection = con; con.Open(); DataTable dtcustsal = new DataTable(); SqlDataAdapter adp = new SqlDataAdapter(cmd); adp.Fill(dtcustsal); if (dtcustsal.Rows.Count > 0) { lbl_mon.Text = dtcustsal.Rows[0]["Months"].ToString(); lbl_yr.Text = yr; GV_Month.DataSource = dtcustsal; GV_Month.DataBind(); //Get Total double GTotal = 0; double QGTotal = 0; // Total for (int j = 0; j < GV_Month.Rows.Count; j++) { Label total = (Label)GV_Month.Rows[j].FindControl("lbl_GTtl"); GTotal += Convert.ToDouble(total.Text); } //Quantity for (int j = 0; j < GV_Month.Rows.Count; j++) { Label totalqty = (Label)GV_Month.Rows[j].FindControl("lbl_Qty"); QGTotal += Convert.ToDouble(totalqty.Text); } ttl_qty.Text = QGTotal.ToString(); lbl_ttl.Text = GTotal.ToString(); } con.Close(); } } catch (Exception ex) { throw ex; } }