using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; namespace FineUIPro.Web.HSSE.EduTrain { public partial class TrainTest : PageBase { /// /// 加载 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT TrainTestId,TrainingId,QsnCode,COrder,QsnContent,QsnAnswer,QsnCategory,QsnKind,QsnImportant,QsnCategoryName" + @",QsnKindName,QsnImportantName,Analysis,Description,UploadTime" + @" FROM View_EduTrain_TrainTest WHERE TrainingId=@TrainingId "; List listStr = new List { new SqlParameter("@TrainingId", Request.Params["TrainingId"]) }; if (!string.IsNullOrEmpty(this.txtQsnContent.Text.Trim())) { strSql += " AND QsnContent LIKE @QsnContent"; listStr.Add(new SqlParameter("@QsnContent", "%" + this.txtQsnContent.Text.Trim() + "%")); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; //tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } /// /// 改变索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { Response.ClearContent(); string filename = Funs.GetNewFileName(); Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("考试试题" + filename, System.Text.Encoding.UTF8) + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; this.Grid1.PageSize = this.Grid1.RecordCount; BindGrid(); Response.Write(GetGridTableHtml(Grid1)); Response.End(); } #endregion } }