Multiview和View控件(有用)

MultiView View 控件和制作出选项卡的效果,MultiView 控件是一组 View 控件的容器。使用它可定义一组 View 控件,其中每个 View 控件都包含子控件。
    如果要切换视图,可以使用控件的ID或者View控件的索引值。在 MultiView 控件中,一次只能将一个 View 控件定义为活动视图。如果某个 View 控件定义为活动视图,它所包含的子控件则会呈现到客户端。可以使用 ActiveViewIndex 属性或SetActiveView 方法定义活动视图。如果 ActiveViewIndex 属性为空,则 MultiView 控件不向客户端呈现任何内容。如果活动视图设置为MultiView 控件中不存在的 View,则会在运行时引发 ArgumentOutOfRangeException
    一些常用的属性、方法:
    ActiveViewIndex属性:用于获取或设置当前被激活显示的View控件的索引值。默认值为-1,表示没有View控件被激活。
    SetActiveView方法:用于激活显示特定的View控件。
    4个静态只读字段:若要允许用户在 MultiView 控件中的 View 控件之间进行导航,可将 LinkButtonButton 控件添加到每个 View 控件。若要利用 MultiView 控件对当前活动 View 进行自动更新,请将按钮或链接按钮的 CommandName 属性设置为与所需导航行为对应的命令名字段的值,这些命令名字段如下:PreviousViewCommandNameNextViewCommandNameSwitchViewByIDCommandNameSwitchViewByIndexCommandName
    ActiveViewChanged事件:当视图切换时被激发。

应用示例:
Default.aspx


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{}
    
    
protected void LBView1_Click(object sender, EventArgs e)
    
{
        MultiView1.ActiveViewIndex 
= 0;        
        Cell1.Attributes[
"class"= "SelectedTopBorder";
        Cell2.Attributes[
"class"= "TopBorder";
        Cell3.Attributes[
"class"= "TopBorder";
    }

    
protected void LBView2_Click(object sender, EventArgs e)
    
{
        MultiView1.ActiveViewIndex 
= 1;
        Cell1.Attributes[
"class"= "TopBorder";
        Cell2.Attributes[
"class"= "SelectedTopBorder";
        Cell3.Attributes[
"class"= "TopBorder";
    }

    
protected void LBView3_Click(object sender, EventArgs e)
    
{
        MultiView1.ActiveViewIndex 
= 2;
        Cell1.Attributes[
"class"= "TopBorder";
        Cell2.Attributes[
"class"= "TopBorder";
        Cell3.Attributes[
"class"= "SelectedTopBorder";
    }

}

 


 

StyleSheet.css

 

posted on 2010-04-02 16:05  隊長  阅读(677)  评论(0)    收藏  举报

导航