返回首页
当前位置: 主页 > 网络编程 > .Net实例教程 >

ASP.NET-多视图

时间:2020-01-14 16:20来源:知行网www.zhixing123.cn 编辑:麦田守望者

 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中的View控件集合。
ActiveViewIndex 从零开始的索引,表示活动视图。如果没有活动的视图,则索引为-1。

与MultiView控件的导航关联的按钮控件的CommandName属性与MultiView控件的某些相关字段关联。

例如,如果将CommandName值为NextView的按钮控件与多视图的导航相关联,则在单击按钮时它将自动导航到下一个视图。

下表显示了上述属性的默认命令名称:

性质 描述
NextViewCommandName 下一个
PreviousViewCommandName 上一个
SwitchViewByIDCommandName SwitchViewByID
SwitchViewByIndexCommandName SwitchViewByIndex

多视图控件的重要方法是:

方法 描述
SetActiveview 设置活动视图
GetActiveview 检索活动视图

每次更改视图时,页面都会被发布回服务器并引发许多事件。一些重要事件是:

大事记 描述
ActiveViewChanged 更改视图时引发
启用 由活动视图引发
停用 由无效视图引发

除了上述属性,方法和事件之外,多视图控件还继承控件和对象类的成员。

示例页面有三个视图。每个视图都有两个用于浏览视图的按钮。

内容文件代码如下:

<%@ 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,因此执行时它将显示第三个视图。

多视图

 
------分隔线----------------------------
标签(Tag):
------分隔线----------------------------
推荐内容
  • ASP.NET-面板控件

    面板控件用作页面上其他控件的容器。 它控制其包含的控件的外观和可见性。 它还允许以...

  • ASP.NET-多视图

    MultiView和View控件使您可以将页面的内容分为不同的组,一次仅显示一个组。 每个View...

  • ASP.NET-日历

    日历控件是功能丰富的Web控件,它提供以下功能: 一次显示一个月 选择一天,一周或一...

  • ASP.NET-广告轮播

    AdRotator控件从列表中随机选择横幅图形,该列表在外部XML计划文件中指定。 该外部XML...

  • ASP.NET-文件上传

    ASP.NET具有两个控件,允许用户将文件上传到Web服务器。 服务器收到发布的文件数据后...

  • ADO.NET

    ADO.NET在前端控件和后端数据库之间提供了桥梁。 ADO.NET对象封装了所有数据访问操作...

猜你感兴趣