protected void Print_OnClick(object sender, EventArgs e) { if (checkDate()) { HPCBusinessLogic.UltilFunc _ultil = new UltilFunc(); DataSet _ds; int intChuyenMuc = 0; int intUser = 0; if (cbo_chuyenmuc.SelectedIndex > 0) { intChuyenMuc = Convert.ToInt32(cbo_chuyenmuc.SelectedValue.ToString()); } if (drop_User.SelectedIndex > 0) { intUser = Convert.ToInt32(drop_User.SelectedValue.ToString()); } _ds = _ultil.GetStoreDataSet("[CMS_SelectAll_News_ByUserID]", new string[] { "@Fromdate", "@Todate", "@cate", "@UserID" }, new object[] { txt_FromDate.Text.Trim(), txt_ToDate.Text.Trim(), intChuyenMuc, intUser }); if (_ds.Tables[0].Rows.Count > 0 && _ds != null) { gvList.DataSource = _ds.Tables[0]; gvList.DataBind(); GridViewToExcel.Export("Ket_Qua_" + DateTime.Now.ToShortDateString().Replace("/", "") + ".xls", gvList, "THỐNG KÊ BÀI VIẾT THEO TÁC GIẢ", "Từ ngày " + txt_FromDate.Text.Trim() + " đến ngày " + txt_ToDate.Text.Trim(), ""); this.gvList.AllowPaging = true; this.gvList.DataBind(); _ds.Dispose(); } else { gvList.DataSource = null; gvList.DataBind(); System.Web.UI.ScriptManager.RegisterStartupScript(this, typeof(string), "Message", "alert('Không có dữ liệu!');", true); return; } } }
/// <summary> /// Export grid to excel /// </summary> /// <param name="fileName">tên file</param> /// <param name="gv">grid view</param> public static void Export(string fileName, GridView gv) { GridViewToExcel.Export(fileName, gv, "", "", ""); }