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 = "StockList.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); GVCashTrans.GridLines = GridLines.Both; GVCashTrans.HeaderStyle.Font.Bold = true; GVCashTrans.RenderControl(htmltextwrtter); Response.Write(strwritter.ToString()); Response.End(); } catch (Exception ex) { throw; //ScriptManager.RegisterStartupScript(this, this.GetType(), "isActive", "Alert();", true); //lblalert.Text = ex.Message; } }
public void getFrmAcc(string frmdat, string cashacc) { try { //q = " select * from v_diffRat where MPurDate <= '" + dat + "' and MPurID ='" + mpurid + "' and CompanyId = '" + Session["CompanyID"] + "' and BranchId= '" + Session["BranchID"] + "'"; q = "select * from v_cashTrans where typeofpay = 'cash' and accno ='" + cashacc + "' and expensesdat ='" + frmdat + "' and CompanyId = '" + Session["CompanyID"] + "' and BranchId= '" + Session["BranchID"] + "'"; dt_ = new DataTable(); dt_ = DBConnection.GetQueryData(q); if (dt_.Rows.Count > 0) { GVCashTrans.DataSource = dt_; GVCashTrans.DataBind(); lbl_dat.Text = dt_.Rows[0]["expensesdat"].ToString(); } } catch (Exception ex) { throw ex; } }