/// <summary> /// Download Excel /// </summary> public void Download() { //接收需要导出的数据 BLL.T_Match_Competition bll = new BLL.T_Match_Competition(); List <Model.T_Match_Competition> list = bll.DataTableToList(bll.GetList("1=1 order by CName asc").Tables[0]); //命名导出表格的StringBuilder变量 System.Text.StringBuilder sHtml = new System.Text.StringBuilder(string.Empty); //打印表头 sHtml.Append("<table border=\"1\" width=\"100%\">"); //sHtml.Append("<tr height=\"40\"><td colspan=\"5\" align=\"center\" style='font-size:24px'><b>学生表" + "</b></td></tr>"); //打印列名 sHtml.Append("<tr height=\"20\" align=\"center\"><td>姓名</td><td>介绍</td><td>附件</td><td>开始时间</td><td>结束时间</td><td>报名开始</td><td>报名结束</td><td>发布者</td></tr>"); //循环读取List集合 for (int i = 0; i < list.Count; i++) { sHtml.Append("<tr height=\"20\" align=\"center\"><td>" + list[i].CName + "</td><td>" + list[i].CIntroduce + "</td><td>" + list[i].CAttachment1 + "</td><td>" + list[i].CStartTime + "</td><td>" + list[i].CEndTime + "</td><td>" + list[i].CApplySTime + "</td><td>" + list[i].CApplyETime + "</td><td>" + list[i].CPublisherName + "</td></tr>"); } //打印表尾 // sHtml.Append("<tr height=\"40\"><td align=\"center\" colspan=\"5\" style='background-color:#CD0000;font-size:24px'><b>XXXXXXXX</a> </b></td></tr>"); sHtml.Append("</table>"); //调用输出Excel表的方法 ExportToExcel("application/ms-excel", "比赛表.xls", sHtml.ToString()); }
// // GET: /Match/MatDetial/ /// <summary> /// Index /// </summary> /// <returns></returns> public ActionResult Index() { BLL.T_Match_Competition bll = new BLL.T_Match_Competition(); //List<Model.T_Match_Competition> lst = bll.GetModelList("1=1"); int PageSize = 10;//默认值 int PageIndex = 1; string keywords = Convert.ToString(Request.Form["keywords"]); if (Request.Form["pageNum"] != null) { PageSize = Convert.ToInt32(Request.Form["numPerPage"]); PageIndex = Convert.ToInt32(Request.Form["pageNum"]); } //读取该页的数据 DataSet ds = bll.GetListByPage("CName like '%" + keywords + "%'", "CID", (PageIndex - 1) * PageSize + 1, PageIndex * PageSize); List <Model.T_Match_Competition> lst = bll.DataTableToList(ds.Tables[0]); int totalcount = bll.GetRecordCount("CName like '%" + keywords + "%'"); ViewBag.pagesize = PageSize; ViewBag.pageindex = PageIndex; ViewBag.lst = lst; ViewBag.totalcount = totalcount; return(View()); }