源代碼:
前台(html):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>郵件列表</title> <link rel="stylesheet" type="text/css" href="../jQuery/themes/default/easyui.css" /> <link rel="stylesheet" type="text/css" href="../jQuery/themes/icon.css" /> <script type="text/javascript" src="../jQuery/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="../jQuery/jquery.easyui.min.js"></script> <script type="text/javascript" language="javascript"> $(function(){ $('#ReceiveList').datagrid({ title:'收件箱', loadMsg:"正在加載,請稍等...", striped: true, fit: true,//自動大小 fitColumns: true, url:'../Common/DealData.ashx?Menu=Mail&MailFolder=Receive',//查看收件箱內容 columns:[[ {field:'MailID',checkbox:true}, {field:'MailSender',title:'發件人',width:120,sortable:true,searchtype:"number"}, {field:'MailSendDate',title:'發件時間',width:120,sortable:true}, {field:'MailSubject',title:'標題',width:200,sortable:true ]], rownumbers:true,//行號 singleSelect:false,//是否單選 pagination:true//分頁控件 }); //設置分頁控件 var p = $('#ReceiveList').datagrid('getPager'); $(p).pagination({ pageSize: 10,//每頁顯示的記錄條數,默認為10 pageList: [10,20,50],//可以設置每頁記錄條數的列表 beforePageText: '第',//頁數文本框前顯示的漢字 afterPageText: '頁 共 {pages} 頁', displayMsg: '當前顯示 {from} - {to} 條記錄 共 {total} 條記錄' }); }); </script> </head> <body class="easyui-layout"> <div region="center" title="列表" style="overflow:hidden;"> <div id="main" class="easyui-tabs" fit="true" border="false"> <div title="首頁" style="padding:20px;overflow:hidden;"> <div style="margin-top:20px;"> 首頁 </div> </div> <div title="收件箱" closable="true" selected="true" style="overflow:hidden;"> <table id="ReceiveList"></table> </div> </div> </div> </body> </html>
后台(DealData.ashx):
using System; using System.Collections; using System.Data; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Collections.Generic; namespace YM.Web.Common { /// <summary> /// $codebehindclassname$ 的摘要說明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class DealData : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //獲取郵件信息,返回Json數據 string strMailFolder = context.Request["MailFolder"]; //rows和page是jQuery默認傳的值(暫時還不知道怎么傳的) int intPageSize = int.Parse(context.Request["rows"].ToString()); int intCurrentPage = int.Parse(context.Request["page"].ToString()); //分頁屬性 YM.Model.PaginationCondition Pcondition = new YM.Model.PaginationCondition(intCurrentPage, intPageSize); string strJson = GetMailToJson(strMailFolder, Pcondition); context.Response.Write(strJson); } public bool IsReusable { get { return false; } } #region 獲取郵件信息 /// <summary> /// 獲取郵件信息 /// </summary> /// <param name="strMailFolder">郵件類型</param> /// <param name="Pcondition">分頁屬性</param> /// <returns>返回Json字符串</returns> public string GetMailToJson(string strMailFolder, YM.Model.PaginationCondition Pcondition) { string strResult = string.Empty; switch (strMailFolder) { case "Receive": //收件箱 YM.BLL.MailBLL mailBLL = new YM.BLL.MailBLL(); YM.Model.Pagination<YM.Model.Mail> mailResult = mailBLL.GetList(Pcondition, ""); //將List轉換為Json(這里要傳“rows”,因為Jquery里面只認rows) strResult = YM.Common.ConvertJson.ListToJson(mailResult.Results, mailResult.TotalCount, "rows"); break; default: break; } return strResult; } #endregion } }