html代码:
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">View 1<br />
<asp:Button ID="Button1" runat="server" CommandArgument="View2" CommandName="SwitchViewByID" Text="Go to View2" />
<asp:Button ID="Button4" runat="server" CommandName="NextView" Text="Next View(2)" />
</asp:View>
<asp:View ID="View2" runat="server">View 2<br />
<asp:Button ID="Button2" runat="server" CommandArgument="View3" CommandName="SwitchViewByID" Text="Go to View 3" />
<asp:Button ID="Button5" runat="server" CommandName="NextView" Text="Next View(3)" />
</asp:View>
<asp:View ID="View3" runat="server">View 3<br />
<asp:Button ID="Button3" runat="server" CommandArgument="View1" CommandName="SwitchViewByID" Text="Go to View 1" />
<asp:Button ID="Button6" runat="server" CommandArgument="View1" CommandName="SwitchViewByID" Text="Next View(1)" />
</asp:View>
</asp:MultiView>
源代码:
if (!IsPostBack)
{
if (Request.QueryString["id"] != null) { MultiView1.ActiveViewIndex = Convert.ToInt32(Request.QueryString["id"]); }
}
在你切换视图之间一般用LinkButton、Button、imageButton,因为只有它们才有CommandName,CommandArgument属性。
CommandName属性值:
PreviousView、NextView、SwitchViewByID 或 SwitchViewByIndex
CommandArgument属性值:与关联的 CommandName 一起被传递到 Command 事件的可选参数。