您需要考虑如何设置页面。有很多方法可以做到这一点。
如果您在页面加载时获得所有记录,则可以将它们分配给各自的控件。为了让它出现,如果它们在许多页面上,您可以使用 MultiView 控件。
标记
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<asp:Label ID="lblRecordOne" runat="server" />
</asp:View>
<asp:View ID="View2" runat="server">
<asp:Label ID="lblRecordTwo" runat="server" />
</asp:View>
</asp:MultiView>
<asp:Button ID="btNext" runat="server">Next</asp:Button>
代码隐藏
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Call your method that loads the data to results
Dim results() As String = loaddata()
'Set the data
lblRecordOne.Text = results(0)
lblRecordTwo.Text = results(1)
End Sub
Protected Sub btNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btNext.Click
'There is a much better way to go about this, but for this
'demos sake here is the basic idea
MultiView1.SetActiveView(View2)
End Sub
您要记住的是,每个 View 控件在 MultiView 内都有一个索引。因此,您需要一种方法来跟踪活动视图是什么。当用户单击下一个按钮时,您将视图前进一个。
就 MVC 应用程序而言
控制器
public class HomeController
{
// /Home/GetRecord/{id}
public ViewResult GetRecord(int? id)
{
int modelID;
if (id == null) { modelID = 0; }
ViewBag.CurrentID = modelID;
// This will send the value to the view
// I would refactor loaddata to only return one record at a time
// based on an id or an index
return View(loaddata(modelID));
}
}
看法
<label>@Model.Result</label>
@Html.ActionLink("GetRecord", "Home", new { id = ViewBag.CurrentID + 1 })
每次您单击 ActionLink 时,它都会通过一个记录集前进。
如果第一条记录是Hello,第二条记录是World:
/Home/GetRecord/0 - 你好
/Home/GetRecord/1 - 世界
抱歉,我将其切换到 C#,我更喜欢徒手编写 C# 而不是 VB。VB中的代码非常相似。如果你需要一个转换器去http://converter.telerik.com/。