using System; using System.Web; using System.Web.UI; public partial class excelExportEventi : System.Web.UI.Page { public override void VerifyRenderingInServerForm(Control control) { // Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time. } private void doExport() { Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=Eventi.xls"); Response.Charset = ""; // If you want the option to open the Excel file without saving than // comment out the line below Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); gvEventi.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } #region area protected protected resoconti _resoconti; protected void Page_Load(object sender, EventArgs e) { _resoconti = new resoconti(); if (!Page.IsPostBack) { aggiornamento(); doExport(); } } protected void reportUpdate() { // alzo l'evento d update/inserimento e ricarico cache... if (eh_doUpdate != null) { eh_doUpdate(this, new EventArgs()); } } #endregion #region area public #region gestione eventi public event EventHandler eh_doUpdate; #endregion /// /// idx della macchina da mostrare /// public string idxMacchina { get { string idxMacchina = "1"; try { idxMacchina = (string)Session["IdxMacchina"]; } catch { } return idxMacchina; } set { Session["IdxMacchina"] = value; } } public string statoDaIdx(object idx) { return _resoconti.statoDaIdx(Convert.ToInt32(idx)); } public string tipoDaIdx(object idx) { return _resoconti.tipoDaIdx(Convert.ToInt32(idx)); } public string macchinaDaIdx(object idx) { return _resoconti.macchinaDaIdx(idx.ToString()); } public void aggiornamento() { gvEventi.AllowPaging = false; //gvEventi.PageSize = _numRighe; ods_EventList.DataBind(); } public void reportUpdt(object sender, EventArgs e) { reportUpdate(); } public string operatoreDaMatr(object matricola) { int matr = 0; try { matr = Convert.ToInt32(matricola); } catch { } return _resoconti.oprDaMatr(matr); } #endregion }