Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concrete idea and code of AJAX and three-tier architecture to realize the paging function?

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shows you AJAX and three-tier architecture to achieve paging specific ideas and code is how, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.

The code is as follows:

-- HTMLPage1.htm--

Table {border:solid 1px # 444; background-color:Aqua;}

Table td {border:solid 1px # 444;}

$(function () {)

Var pageindex = 1

Var pagesize = 10

Var lastpageindex = 1

Loaddata ()

Function loaddata () {

$.ajax ({

Type: "post"

ContentType: "application/json"

Url: "WebService1.asmx/GetListAjax"

Data: "{pagesize:" + pagesize + ", pageindex:" + pageindex + "}"

Success: function (result) {

Var strtable =''

Strtable + = 'numbered title content creation time'

For (var I = 0; I

< result.d.length; i++) { strtable += ''; strtable += '' + result.d[i].Id + ''; strtable += '' + result.d[i].NewsTitle + ''; strtable += '' + result.d[i].NewsContent + ''; strtable += '' + result.d[i].CreateTime + ''; strtable += ''; } strtable += ''; $('#mydiv').html(strtable); } }) } $.ajax({ type: "post", contentType: "application/json", url: "WebService1.asmx/GetLastPageindex", data: "{pagesize:" + pagesize + "}", success: function (result) { lastpageindex = result.d; } }) //第一页 $('a:first').click(function () { pageindex = 1; loaddata(); }) //上一页 $('#divfenye a:eq(1)').click(function () { if (pageindex >

1) {

Pageindex--

Loaddata ()

}

})

/ / next page

$('# divfenye a:eq (2)') .click (function () {

If (pageindex < lastpageindex) {

Pageindex++

Loaddata ()

}

})

/ / Last page

$('# divfenye a:eq (3)') .click (function () {

Pageindex = lastpageindex

Loaddata ()

})

$('# divfenye aVLA Last') .click (function () {

Pageindex = $('# txtPageindex') .val ()

Loaddata ()

})

$('# txtPageindex') .focus (function () {

$(this) .val ('')

})

})

Page 1 previous page next page last page Go

-WebService1--

/ / to allow this Web service to be called from a script using ASP.NET AJAX, uncomment the following line.

[System.Web.Script.Services.ScriptService]

Public class WebService1: System.Web.Services.WebService

{

[WebMethod]

Public string HelloWorld ()

{

Return "Hello World"

}

[WebMethod]

Public List GetListAjax (int pagesize, int pageindex)

{

BLL.T_News1 bnews = new BLL.T_News1 ()

DataTable dt = bnews.GetListDataTable (pagesize, pageindex)

List list = new List ()

Int Id

String newstitle = ""

String newscontent = ""

DateTime createtime

For (int I = 0; I < dt.Rows.Count; iTunes +)

{

Id = Convert.ToInt32 (dt.Rows [I] ["Id"])

Newstitle = dt.Rows [I] ["NewsTitle"] .ToString ()

Newscontent = dt.Rows [I] ["NewsContent"] .ToString ()

Createtime = Convert.ToDateTime (dt.Rows [I] ["CreateTime"])

Model.T_News1 news = new Model.T_News1 ()

{

Id = Id

NewsTitle = newstitle

NewsContent = newscontent

CreateTime = createtime

}

List.Add (news)

}

Return list

}

[WebMethod]

Public int GetLastPageindex (int pagesize)

{

BLL.T_News1 bnews = new BLL.T_News1 ()

Int totalcount = bnews.GetRecordCount ("")

If (totalcount% pagesize = = 0)

{

Return totalcount / pagesize

}

Else

{

Return totalcount / pagesize + 1

}

}

-DAL layer:--

/ / /

/ / get the data list by paging

/ / /

Public DataTable GetListDataTable (int PageSize, int PageIndex)

{

SqlParameter [] parameters = {

New SqlParameter (@ PageSize, SqlDbType.Int)

New SqlParameter (@ PageIndex, SqlDbType.Int)

}

Parameters [0] .value = PageSize

Parameters [1] .value = PageIndex

Return DbHelperSQL.RunProcedureDataTable ("pro_fenye", parameters)

}

-BLL layer:--

Public DataTable GetListDataTable (int pagesize, int pageindex)

{

Return dal.GetListDataTable (pagesize, pageindex)

}

-DbHelperSQL:

Public static DataTable RunProcedureDataTable (string storedProcName, IDataParameter [] parameters)

{

Using (SqlConnection connection = new SqlConnection (connectionString))

{

DataTable dt = new DataTable ()

Connection.Open ()

SqlDataAdapter sqlDA = new SqlDataAdapter ()

SqlDA.SelectCommand = BuildQueryCommand (connection, storedProcName, parameters)

SqlDA.Fill (dt)

Connection.Close ()

Return dt

}

}

The above content is AJAX and three-tier architecture to achieve paging function specific ideas and code is how, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report