Jquery结合Ajax和Web服务使用三层架构实现无刷新分页
admin
2024-01-20 11:44:57

在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;}


 

相关内容

热门资讯

春节档的“上海限定”:电影好看... 今年的电影春节档含“沪”量满满——上影出品《星河入梦》、上影联合出品《惊蛰无声》和上海联和院线联合出...
冬奥会|小科普:有的摔倒能晋级... 来源:新华社 新华社米兰2月15日电(记者李嘉、丁文娴、高萌)14日晚进行的米兰冬奥会短道速滑男子1...
从5圈返回到3圈自主快速返回 ... 本文转自【央视新闻客户端】;神舟二十号舷窗异常情况出现后,2025年11月10日,中国载人航天工程总...
多地金融监管局迎来“85后”副... 近段时间,多地金融监管局更新了局领导信息,多名“85后”履新副局长。澎湃新闻注意到,毛竹青已任河北金...
凯西.沃瑟曼将出售麾下艺人经纪...   凯西.沃瑟曼(Casey Wasserman)上周五晚间在一份给员工的内部通知中表示,他将出售以...