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,因?yàn)橹挥兴鼈儾庞蠧ommandName,CommandArgument屬性。
CommandName屬性值:
PreviousView、NextView、SwitchViewByID 或 SwitchViewByIndex
CommandArgument屬性值:與關(guān)聯(lián)的 CommandName 一起被傳遞到 Command 事件的可選參數(shù)。