asp.net中利用Jquery+Ajax+Json实现无刷新分页的实例代(3)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
//新增  
using System.Web.Script.Serialization;
using System.Text;


public partial class SupplyAJAX : System.Web.UI.Page
{
    protected static List<Student> StudentList = new List<Student>();
    protected static int RecordCount = 0;
    protected static DataTable dt = CreateDT();
    protected void Page_Load(object sender, EventArgs e)
    {
        switch (Request["type"])
        {
            case "show":
                #region 分页配置
                //具体的页面数
                int pageIndex;
                int.TryParse(Request["pageIndex"], out pageIndex);
                //页面显示条数
                int PageSize = Convert.ToInt32(Request["pageSize"]);
                if (pageIndex == 0)
                {
                    pageIndex = 1;
                }
                #endregion
                DataTable PagedDT = GetPagedTable(dt, pageIndex, PageSize);
                List<Student> list = new List<Student>();
                foreach (DataRow dr in PagedDT.Rows)
                {
                    Student c = new Student();
                    c.Id = (Int32)dr["Id"];
                    c.Name = dr["Name"].ToString();
                    c.Sex = dr["Sex"].ToString();
                    list.Add(c); 
                }
                string json = new JavaScriptSerializer().Serialize(list);//这个很关键,否则error
                StringBuilder Builder = new StringBuilder();
                Builder.Append("{");
                Builder.Append("\"recordcount\":" + RecordCount + ",");
                Builder.Append("\"data\":");
                Builder.Append(json);
                Builder.Append("}");
                Response.ContentType = "application/json";
                Response.Write(Builder.ToString());
                break;
            case "getcount":
                Response.Write(dt.Rows.Count);
                break;
            case "add":
                break;
            case "update":
                break;
            case "delete":
                break;
        }
        Response.End();
    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzsgs.html