我正在尝试使用多视图控件。我首先创建一些视图并在 preinit 事件中添加一些标签。在 (!isPostBack) 场景中将它们添加到多视图中。我想使用“下一个”和“上一个”按钮在视图之间导航。这就是我所做的:
protected void Page_PreInit(object sender, EventArgs e)
{
if (IsPostBack)
{
MultiView1 = (MultiView)Session["multi"];
}
else
{
View view1 = new View();
View view2 = new View();
View view3 = new View();
Label l1 = new Label(); l1.Text = "1";
Label l2 = new Label(); l2.Text = "2";
Label l3 = new Label(); l3.Text = "3";
view1.Controls.Add(l1);
view2.Controls.Add(l2);
view3.Controls.Add(l3);
MultiView1.Views.Add(view1);
MultiView1.Views.Add(view2);
MultiView1.Views.Add(view3);
MultiView1.ActiveViewIndex = 0;
Session["multi"] = MultiView1;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex++;
}
protected void Button1_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex--;
}
这将不起作用,就好像多视图不保存它的内容并且不允许我将 activeviewindex 更改为大于 0 的值一样。如何修改它以便允许我更改 activeviewindex?