MultiView和View控件

        通过一个MultiView控件和其中定义的多个View控件,可以切换视图,用到的方法是SetActiveView和ActiveViewIndex方法。

1、SetActiveView方法:MultiView1.SetActiveView(View1);View1是aspx中设置的View控件的ID

2、ActiveViewIndex方法:MultiView1.ActiveViewIndex = 0;0是索引,该方法通过索引来切换活动视图。View控件的索引是由它在 MultiView控件中的声明顺序确定的。例如,在 MultiView控件中声明的第一个 View 控件的索引为 0。

通过下面的实例来展示:

aspx页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MultiView.aspx.cs" Inherits="testTestTest.MultiViewTest.MultiView" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:LinkButton ID="LinkButton1" runat="server" οnclick="LinkButton1_Click">first</asp:LinkButton>   
        <asp:LinkButton ID="LinkButton2" runat="server" οnclick="LinkButton2_Click">second</asp:LinkButton>   
        <asp:LinkButton ID="LinkButton3" runat="server" οnclick="LinkButton3_Click">third</asp:LinkButton>   
        <br />  
        <hr />  
        <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex = 1>  
            <asp:View ID="View1" runat="server">  
            this is the first page  
            </asp:View>  
            <asp:View ID="View2" runat="server">  
            this is the second page  
            </asp:View>     
            <asp:View ID="View3" runat="server">  
            this is the third page  
            </asp:View>                 
        </asp:MultiView> 

    </div>
    </form>
</body>
</html>

cs页面:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace testTestTest.MultiViewTest
{
    public partial class MultiView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            MultiView1.SetActiveView(View1);
        }
        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 1;
        }
        protected void LinkButton3_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 2;
        } 
    }
}

可以实现切换视图



  • 1
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值