当前位置:编程学习 > JAVA >>

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

在Web服务里代码

[html]  /// <summary> 
    /// WebService1 的摘要说明 
    /// </summary> 
    [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<Model.T_Student> GetListAjax(int pageindex,int pagesize) { 
            BLL.T_Student bll = new BLL.T_Student(); 
            int count= bll.GetRecordCount(""); 
            DataTable dt = bll.GetListDataTable(pageindex, pagesize); 
            List<Model.T_Student> li = new List<Model.T_Student>(); 
            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; 
            } 
        } 
    } 

/// <summary>
    /// WebService1 的摘要说明
    /// </summary>
    [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<Model.T_Student> GetListAjax(int pageindex,int pagesize) {
            BLL.T_Student bll = new BLL.T_Student();
            int count= bll.GetRecordCount("");
            DataTable dt = bll.GetListDataTable(pageindex, pagesize);
            List<Model.T_Student> li = new List<Model.T_Student>();
            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;
      &nbs

补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,