如何在客户端对类数组执行手动分页? [英] How can I perform a manual paging on class-array in client side?

查看:87
本文介绍了如何在客户端对类数组执行手动分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

如何在客户端对类数组执行手动分页?我的目的是在页面中显示tourList []记录,每页最多10条记录.当我单击页码时,应发生回发,然后将其他记录带入被单击的页.

我尝试了几种方法,但由于页码的超链接而无法成功.我什至尝试使用ASP:LINKBUTTON,但是每当发生回发时,tourList []就会为null.所以我松了tourList. :(

服务器端

Hello,

How can I perform a manual paging on class-array in client side? My aim is to show tourList[] records in pages with a limit of 10 records for per page. When I click the page numbers, the postback should occur and then bring the other records for clicked page.

I tried several ways but I couldn''t succeed it because of HyperLinks for the page numbers. I even tried with the ASP:LINKBUTTON but whenever postback occurs, tourList[] becomes null. So I loose the tourList. :(

SERVER SIDE

// the following the array of class is populated at server side. I successfully 
// display the all records but not in paging.

protected PSSaleWS.TourPackageSearchResultItem[] tourList;





如果您向我展示如何解决问题,我将非常感谢您的帮助.

谢谢.





if you show me how to solve the problem, I would really appreciate your help.

Thanks.

推荐答案

您发布的小代码看起来像一个成员变量,可能是您的ASP .Net网页的成员变量.如果是这样,那么以这种方式工作不是一个好主意.

为什么?这很简单.回发之间的服务器上不存在该页面.在每个请求(包括回发)时,都会创建该页面的新实例,执行一系列事件,并在发送响应后销毁该实例.

回发后,这是一个从未填充您的数组的新页面.您应该查看几件事以更好地了解发生了什么:

ASP.Net页面生命周期 [数据绑定 [ ViewState [
The little code you have posted looks like a member variable, probably of your ASP .Net webpage. If that''s so, it''s not a good idea to work that way.

Why? That''s easy. The page does not exist on the server between postbacks. At every request (including postbacks) a new instance of the page is created, performs a sequence of events and is destroyed when the response has been sent.

After a postback it''s a new page where your array has never been filled. There are several things you should look at to better understand what''s going on:

ASP.Net page lifecycle[^]

Data binding[^]

Alternatively, you can do manual paging and not use data binding. In this case you must store your array in the ViewState and restore it from there at every call to PageLoad(). Also, you must fill the control yourself after every postback. This should also be done at PageLoad(), right after restoring the array from the ViewState.

ViewState[^]


这篇关于如何在客户端对类数组执行手动分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆