国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ASP.NET中實現Ajax分頁

2019-11-17 01:36:31
字體:
來源:轉載
供稿:網友

asp.net中實現Ajax分頁

在頁面中指定一個div容器來接收動態生成的分頁數據:

1 <div id="div_menu">2 </div>

使用jQuery來請求并處理Json格式數據:

 1 //定義頁碼與頁容量 2         var pageIndex = 1; 3         var pageSize = 15; 4         var pageCount = 0; 5         var recordCount = 0; 6         AjaxGetData(pageIndex, pageSize); 7         //Ajax獲取數據 8         function AjaxGetData(index, size) { 9             $.ajax({10                 url: "SEOver='javascrxmlHttpRequest, textStatus, errorThrown) {37                     alert(xmlhttpRequest);38                     alert(textStatus);39                     alert(errorThrown);40                 }41             });42         }43         //前一頁44         function GoToPrePage() {45             pageIndex -= 1;46             if (pageIndex < 1) {47                 pageIndex = 1;48                 return;49             }50             AjaxGetData(pageIndex, pageSize);51         }52         //后一頁53         function GoToNextPage() {54             pageIndex += 1;55             if (pageIndex > pageCount) {56                 pageIndex = pageCount;57                 return;58             }59             AjaxGetData(pageIndex, pageSize);60         } 

新建一個一般處理程序,來處理Ajax的異步請求:

  1 private readonly BLL.D_Accounting_Entry_Exercise bll = new BLL.D_Accounting_Entry_Exercise();  2         private string _action = "0";  3         protected void Page_Load(object sender, EventArgs e)  4         {  5             Int32 pageIndex = Int32.MinValue;  6             Int32 pageSize = Int32.MinValue;  7   8             if (Request["action"] != null)  9                 this._action = Request["action"]; 10  11             JavaScriptSerializer jss = new JavaScriptSerializer(); 12             if (Request["pageindex"] != null) 13             { 14                 pageIndex = Int32.Parse(Request["pageindex"].ToString()); 15                 pageSize = Request["pagesize"] != null ? Int32.Parse(Request["pagesize"].ToString()) : 10; 16  17                 //處理接收到的數據 18                 int start = 0; 19                 int end = 0; 20  21                 if (this._action == "0") 22                 { 23                     int recordCount = getAllCount(); 24                     int pageCount = (int)Math.Ceiling(((double)recordCount) / ((double)pageSize)); 25                     if (pageIndex > pageCount) 26                     { 27                         pageIndex = pageCount; 28                     } 29                     else if (pageIndex < 1) 30                         pageIndex = 1; 31                     start = (pageIndex - 1) * pageSize + 1; 32                     end = pageIndex * pageSize; 33  34                     IList<Exercise> exerciseLists = new List<Exercise>(); 35                     Exercise exercise = null; 36                     DataSet set = GetDataFromDB(start, end); 37                     int id = 0; 38                     for (int i = 0; i < set.Tables[0].Rows.Count; i++) 39                     { 40                         //將第一行記錄的ID存入session 41                         Session["first_id"] = set.Tables[0].Rows[0]["question_id"]; 42                         exercise = new Exercise(); 43                         id = Convert.ToInt32(set.Tables[0].Rows[i]["question_id"].ToString()); 44                         exercise._question_id = id; 45                         exercise._question_content = set.Tables[0].Rows[i]["question_content"].ToString(); 46                         exercise._question_answer = set.Tables[0].Rows[i]["question_answer"].ToString(); 47                         exercise._question_analyze = set.Tables[0].Rows[i]["question_analyze"].ToString(); 48                         exercise._question_status = Convert.ToInt32(set.Tables[0].Rows[i]["question_status"].ToString()); 49                         exercise._user_id = Convert.ToInt32(set.Tables[0].Rows[i]["user_id"].ToString()); 50                         exercise._add_time = Convert.ToDateTime(set.Tables[0].Rows[i]["add_time"].ToString()); 51                         exercise._row_number = Convert.ToInt32(set.Tables[0].Rows[i]["Row"].ToString()); 52                         exerciseLists.Add(exercise); 53                     } 54                     if (exerciseLists.Count > 0) 55                     { 56                         Response.Write("{/"Count/":" + recordCount + ",/"Exercise_object/":" + jss.Serialize(exerciseLists) + "}"); 57                     } 58                     else 59                     { 60                         Response.Write("{/"Count/":0,/"Exercise_object/":null}"); 61                     } 62                     Response.End(); 63                 } 64                 else if (this._action == "1") 65                 { 66                     string classID = Request["classid"]; 67                     string opSign = Request["opsign"]; 68                     int recordCount = GetYSPXCount(opSign, classID); 69                     int pageCount = (int)Math.Ceiling(((double)recordCount) / ((double)pageSize)); 70                     if (pageIndex > pageCount) 71                     { 72                         pageIndex = pageCount; 73                     } 74                     else if (pageIndex < 1) 75                         pageIndex = 1; 76                     start = (pageIndex - 1) * pageSize + 1; 77                     end = pageIndex * pageSize; 78  79                     IList<OperationModel> operList = new List<operationModel>(); 80                     operationModel model = null; 81                     DataSet set = GetYSPXRecords(start.ToString(), end.ToString(), classID, opSign); 82                     for (int i = 0; i < set.Tables[0].Rows.Count; i++) 83                     { 84                         model = new operationModel(); 85                         model.OD_ID = int.Parse(set.Tables[0].Rows[i]["od_id"].ToString()); 86                         model.OD_TITLE = set.Tables[0].Rows[i]["od_title"].ToString(); 87                         model._row_number = Convert.ToInt32(set.Tables[0].Rows[i]["Row"].ToString()); 88                         operList.Add(model); 89                     } 90                     if (operList.Count > 0) 91
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 社会| 邻水| 阿拉善盟| 红河县| 格尔木市| 安图县| 邛崃市| 衡阳市| 安平县| 芷江| 灵丘县| 克山县| 三穗县| 漾濞| 都匀市| 武夷山市| 通城县| 开化县| 津南区| 晴隆县| 永春县| 临夏市| 综艺| 东阿县| 民丰县| 乃东县| 多伦县| 天门市| 湘阴县| 余江县| 高安市| 浑源县| 临西县| 昌都县| 郧西县| 林甸县| 兴海县| 万安县| 兴国县| 柘荣县| 磐石市|