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 = "VendorPurList.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_VenPur.GridLines = GridLines.Both; GV_VenPur.HeaderStyle.Font.Bold = true; GV_VenPur.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_vensal(string Venid) { try { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "select * from v_DailyPur where PayAcc = " + Venid + " and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'"; cmd.Connection = con; con.Open(); DataTable dtvenpur = new DataTable(); SqlDataAdapter adp = new SqlDataAdapter(cmd); adp.Fill(dtvenpur); if (dtvenpur.Rows.Count > 0) { lbl_ven.Text = dtvenpur.Rows[0]["suppliername"].ToString(); lbl_add.Text = dtvenpur.Rows[0]["addressOne"].ToString(); lbl_phno.Text = dtvenpur.Rows[0]["phoneno"].ToString(); GV_VenPur.DataSource = dtvenpur; GV_VenPur.DataBind(); } con.Close(); } } catch (Exception ex) { throw ex; } }