MultiView和View控件使您可以将页面的内容分为不同的组,一次仅显示一个组。每个View控件管理一组内容,并且所有View控件都放在MultiView控件中。 MultiView控件负责一次显示一个View控件。显示的视图称为活动视图。 MultiView控件的语法为: <asp:MultView ID= "MultiView1" runat= "server"> </asp:MultiView> View控件的语法为: <asp:View ID= "View1" runat= "server"> </asp:View> 但是,视图控件不能单独存在。如果您尝试单独使用它,将导致错误。它始终与Multiview控件一起使用,例如: <asp:MultView ID= "MultiView1" runat= "server"> <asp:View ID= "View1" runat= "server"> </asp:View> </asp:MultiView> 视图和多视图控件的属性View和MultiView控件均派生自Control类,并继承其所有属性,方法和事件。View控件最重要的属性是Boolean类型的Visible属性,该属性设置视图的可见性。 MultiView控件具有以下重要属性:
与MultiView控件的导航关联的按钮控件的CommandName属性与MultiView控件的某些相关字段关联。 例如,如果将CommandName值为NextView的按钮控件与多视图的导航相关联,则在单击按钮时它将自动导航到下一个视图。 下表显示了上述属性的默认命令名称:
多视图控件的重要方法是:
每次更改视图时,页面都会被发布回服务器并引发许多事件。一些重要事件是:
除了上述属性,方法和事件之外,多视图控件还继承控件和对象类的成员。 例示例页面有三个视图。每个视图都有两个用于浏览视图的按钮。 内容文件代码如下: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="multiviewdemo._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title> Untitled Page </title> </head> <body> <form id="form1" runat="server"> <div> <h2>MultiView and View Controls</h2> <asp:DropDownList ID="DropDownList1" runat="server" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> </asp:DropDownList> <hr /> <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="2" onactiveviewchanged="MultiView1_ActiveViewChanged" > <asp:View ID="View1" runat="server"> <h3>This is view 1</h3> <br /> <asp:Button CommandName="NextView" ID="btnnext1" runat="server" Text = "Go To Next" /> <asp:Button CommandArgument="View3" CommandName="SwitchViewByID" ID="btnlast" runat="server" Text ="Go To Last" /> </asp:View> <asp:View ID="View2" runat="server"> <h3>This is view 2</h3> <asp:Button CommandName="NextView" ID="btnnext2" runat="server" Text = "Go To Next" /> <asp:Button CommandName="PrevView" ID="btnprevious2" runat="server" Text = "Go To Previous View" /> </asp:View> <asp:View ID="View3" runat="server"> <h3> This is view 3</h3> <br /> <asp:Calendar ID="Calender1" runat="server"></asp:Calendar> <br /> <asp:Button CommandArgument="0" CommandName="SwitchViewByIndex" ID="btnfirst" runat="server" Text = "Go To Next" /> <asp:Button CommandName="PrevView" ID="btnprevious" runat="server" Text = "Go To Previous View" /> </asp:View> </asp:MultiView> </div> </form> </body> </html> 请注意以下几点: MultiView.ActiveViewIndex确定将显示哪个视图。这是页面上唯一呈现的视图。当没有显示视图时,ActiveViewIndex的默认值为-1。由于在示例中ActiveViewIndex被定义为2,因此执行时它将显示第三个视图。 |