ASP.NET next/previous buttons to display single row in a form

不羁岁月 提交于 2019-12-11 05:27:09

问题


I'm looking for the best way to implement this in ASP.NET.

On the page, the user has an option to "page" through subscription numbers with next and previous buttons.

When the user clicks the next/previous buttons, the page is posted back (partial, AJAX) and the subscription details is displayed in a form. There is only one row displayed at a time.

There is like 10,000 subscription numbers, so if we can avoid loading all the subscription numbers on every postback, we would prefer that.

Somehow I need a counter to keep track of total items and the current position, no? If thats so, how would you store them so they persist on postback?

Thanks in advance. Help is much appreciated.


回答1:


You can create property variables on the page and store the values in the Page's ViewState. Here's an example:

public int CurrentPosition
{
  get{return (int)(ViewState["CurrentPosition"] ?? 0);}
  set{ViewState["CurrentPosition"] = value;}
}

In this example, between postbacks, whether full or partial, the value saved in the CurrentPosition property will be persisted.

Initially CurrentPosition will equal 0, then in your query retrieve using like WHERE ID = CurrentPosition + 1, then increase the value of CurrentPosition by one. If navigating back in the results, decrease by 1.



来源:https://stackoverflow.com/questions/1014526/asp-net-next-previous-buttons-to-display-single-row-in-a-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!