MultiView 控件是一组 View 控件的容器。使用它可定义一组 View 控件,其中每个 View 控件都包含子控件。
用 ActiveViewIndex 属性或SetActiveView 方法定义活动视图。如果 ActiveViewIndex 属性为空,则 MultiView 控件不向客户端呈现任何内容。
如果活动视图设置为MultiView 控件中不存在的 View,则会在运行时引发 ArgumentOutOfRangeException。
ActiveViewIndex属性:用于获取或设置当前被激活显示的View控件的索引值。默认值为-1,表示没有View控件被激活。
首先,添加web窗体,在页面前面加上如下代码
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">first</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">second</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" onclick="LinkButton3_Click">third</asp:LinkButton>
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex ="0">
<asp:View ID="View1" runat="server">
this is the first page
</asp:View>
<asp:View ID="View2" runat="server">
this is the second page
</asp:View>
<asp:View ID="View3" runat="server">
this is the third page
</asp:View>
</asp:MultiView>
在页面后面加上如下代码:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e) {
this.MultiView1.ActiveViewIndex = 0;
}
protected void LinkButton2_Click(object sender, EventArgs e) {
this.MultiView1.ActiveViewIndex = 1;
}
protected void LinkButton3_Click(object sender, EventArgs e) {
this.MultiView1.ActiveViewIndex = 2;
}
保存后运行,即可显示像选项卡的效果,这种方法会刷新页面