温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ASP.NET中如何使用MultiView和View选项卡控件

发布时间:2021-07-15 16:41:52 来源:亿速云 阅读:260 作者:Leah 栏目:开发技术

ASP.NET中如何使用MultiView和View选项卡控件,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

创建新的 ASP.NET 网站项目

1.在“文件”菜单中,指向“新建”,然后选择“网站”。

2.在“新建网站”对话框中,从“语言”下拉列表中选择 Visual C#,并选择 ASP.NET 网站模板。

3.在“位置”中,选择 HTTP 并键入网站的 URL。默认的 URL 为 http://localhost/WebSite。改为http://localhost/MultiViewTest,单击“确定”。

4. 打开Default.aspx设计器,切换到代码区,Ctrl+A全选,替换为以下代码:

复制代码 代码如下:


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_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>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">first</asp:LinkButton>
    <asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">second</asp:LinkButton>
    <asp:LinkButton ID="LinkButton3" runat="server" onclick="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>

对以上代码的解释:

MultiView 和 View Web 服务器控件用作其他控件和标记的容器,并提供了一种可方便地显示信息的替换视图的方式。

MultiView 控件用作一个或多个 View 控件的外部容器。View 控件又可包含标记和控件的任何组合。

MultiView 控件一次显示一个 View 控件,并公开该 View 控件内的标记和控件。通过设置 MultiView 控件的ActiveViewIndex 属性,可以指定当前可见的 View 控件。

简单的说,MultiView是一个父容器,它包括3个View容器。通过ActiveViewIndex=1属性指明index为1的View容器显示,其他两个隐藏。(index按照view排列的顺序从0开始)

5. 打开Default.aspx.cs,   按Ctrl+A全选,删除后替换为以下代码:

复制代码 代码如下:


using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        this.MultiView1.ActiveViewIndex = 0;
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        this.MultiView1.ActiveViewIndex = 1;
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        this.MultiView1.ActiveViewIndex = 2;
    }
}

6.保存后按Ctrl+F5启动运行,如果一切顺利,您可以看到以下界面:

ASP.NET中如何使用MultiView和View选项卡控件

点击first,second,third选项卡,可以切换内容。

看完上述内容,你们掌握ASP.NET中如何使用MultiView和View选项卡控件的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI