• Jquery结合Ajax和Web服务使用三层架构实现无刷新分页


    Web服务里代码

    /// 
        /// WebService1 的摘要说明
        /// 
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
        [System.Web.Script.Services.ScriptService]
        public class WebService1 : System.Web.Services.WebService
        {
    
            [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }
            [WebMethod]
            public List GetListAjax(int pageindex,int pagesize) {
                BLL.T_Student bll = new BLL.T_Student();
                int count= bll.GetRecordCount("");
                DataTable dt = bll.GetListDataTable(pageindex, pagesize);
                List li = new List();
                string name = "";
                int age;
                string gender = "";
                foreach (DataRow row in dt.Rows)
                {
                    name = row["sName"].ToString();
                    age =Convert.ToInt32(row["sAge"]);
                    gender = row["sGender"].ToString();
                    Model.T_Student model = new Model.T_Student();
                    model.sName = name;
                    model.sAge = age;
                    model.sGender = gender;
                    li.Add(model);
                }
                return li;
            }
            [WebMethod]
            public int GetLastPageindex(int pagesize)
            {
                BLL.T_Student bnews = new BLL.T_Student();
                int totalcount = bnews.GetRecordCount("");
                if (totalcount % pagesize == 0)
                {
                    return totalcount / pagesize;
                }
                else
                {
                    return totalcount / pagesize + 1;
                }
            }
        }


    html页代码

    
        


     


    Bll层

    private readonly 分页一小时内完成.SQLServerDAL.T_Student dal = new SQLServerDAL.T_Student();
    public T_Student()
    {}
            public DataTable GetListDataTable(int PageIndex, int PageSize) {
                return dal.GetListDataTable(PageSize, PageIndex);
            }


    DAL层

    public DataTable GetListDataTable(int PageSize, int PageIndex)
            {
                SqlParameter[] parameters = {
    new SqlParameter("@sindex", SqlDbType.Int),
    new SqlParameter("@ssize", SqlDbType.Int),
    };
                parameters[0].Value = PageIndex;
                parameters[1].Value = PageSize;
                return DbHelperSQL.RunProcedureDataTable("usp_student1", parameters);
            }


    DataAccess

    public static DataTable RunProcedureDataTable(string storedProcName, IDataParameter[] parameters)
            {
                SqlConnection connection = new SqlConnection(connectionString);
                DataTable dt = new DataTable();
                connection.Open();
                SqlCommand command = BuildQueryCommand(connection, storedProcName, parameters);
                command.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                adapter.Fill(dt);
                connection.Close();
                return dt;
    
            }


     

  • 相关阅读:
    代码随想录-刷题第一天
    【网络安全 --- kali2022安装】kali2022 超详细的安装教程(提供镜像)
    360安全大模型为什么是“非卖品”?
    Hadoop 学习笔记三 --JobClient 的执行过程
    Linux系统编程——总结初识Linux(常用命令、特点、常见操作系统)
    SpringBoot学习(三)——yaml语法
    Android测试常用的adb命令
    超好用的数据库检索工具介绍——Bean Searcher
    C#操作MySQL从入门到精通(22)——创建表与操纵表
    count(*) 和 count(1) 有什么区别?哪个性能最好?
  • 原文地址:https://blog.csdn.net/xxpr_ybgg/article/details/127748705