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); GVBnkTrans.GridLines = GridLines.Both; GVBnkTrans.HeaderStyle.Font.Bold = true; GVBnkTrans.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 FillGrid(string CheqDat, string date) { try { //q = " select * from v_diffRat where MPurDate <= '" + dat + "' and MPurID ='" + mpurid + "' and CompanyId = '" + Session["CompanyID"] + "' and BranchId= '" + Session["BranchID"] + "'"; q = "select * from v_bnkTrans where typeofpay in ('Cheque','Both') and Chqdat ='" + CheqDat + "' and CompanyId = '" + Session["CompanyID"] + "' and BranchId= '" + Session["BranchID"] + "'"; dt_ = new DataTable(); dt_ = DBConnection.GetQueryData(q); if (dt_.Rows.Count > 0) { GVBnkTrans.DataSource = dt_; GVBnkTrans.DataBind(); lbl_dat.Text = dt_.Rows[0]["expensesdat"].ToString(); } } catch (Exception ex) { throw ex; } }