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 = "VendorCreditList.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_VenCre.GridLines = GridLines.Both; GV_VenCre.HeaderStyle.Font.Bold = true; GV_VenCre.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_vencre() { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "select * from v_crestvenwis"; cmd.Connection = con; con.Open(); DataTable dtvencre = new DataTable(); SqlDataAdapter adp = new SqlDataAdapter(cmd); adp.Fill(dtvencre); if (dtvencre.Rows.Count > 0) { GV_VenCre.DataSource = dtvencre; GV_VenCre.DataBind(); //Get Total double GTotal = 0; double QGTotal = 0; // Out Standing for (int j = 0; j < GV_VenCre.Rows.Count; j++) { Label total = (Label)GV_VenCre.Rows[j].FindControl("lbl_outstand"); GTotal += Convert.ToDouble(total.Text); } //Cash Amount for (int j = 0; j < GV_VenCre.Rows.Count; j++) { Label totalqty = (Label)GV_VenCre.Rows[j].FindControl("lbl_cshamt"); QGTotal += Convert.ToDouble(totalqty.Text); } ttl_qty.Text = QGTotal.ToString(); lbl_ttl.Text = GTotal.ToString(); } con.Close(); } }