asp.net中MultiView和View


小例子

.aspx代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="2_MultiView.aspx.cs" Inherits="_2_MultiView" %>

<!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>
    <h2>Multiview & View 应用程序</h2>
    <p>MV可以看成是一个大容器,V是多个互斥的小容器,只能显示其中1个</p>
    <hr />


        <asp:MultiView ID="mv1" runat="server" ActiveViewIndex="0">
            <asp:View ID="V_Q1" runat="server">
                您有手机么?<asp:RadioButtonList ID="rbl_1" runat="server" 
                    AutoPostBack="True" 
                    onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
                    <asp:ListItem Value="1">有</asp:ListItem>
                    <asp:ListItem Value="0">没有</asp:ListItem>
                </asp:RadioButtonList>
            </asp:View>


            <asp:View ID="V_no" runat="server">
            <p>那就买一个吧!</p>
                <asp:Button ID="Button1" runat="server" Text="OK!" οnclick="Button1_Click" />
                <asp:Button ID="Button3" runat="server" Text="NO,Thanks!" 
                    οnclick="Button3_Click"  />

            </asp:View>

            <asp:View ID="V_Q2" runat="server">
            <p>选择手机的品牌:<asp:RadioButtonList ID="RadioButtonList1" runat="server" 
                    CellPadding="2" CellSpacing="2" RepeatDirection="Horizontal" 
                    AutoPostBack="True" 
                    onselectedindexchanged="RadioButtonList1_SelectedIndexChanged1">
                <asp:ListItem>NOKIA</asp:ListItem>
                <asp:ListItem>SAMSUM</asp:ListItem>
                <asp:ListItem>HTC</asp:ListItem>
                <asp:ListItem>APPLE</asp:ListItem>
                <asp:ListItem>其他</asp:ListItem>
                </asp:RadioButtonList>
                </p>
            </asp:View>
            <asp:View ID="V_DONE" runat="server">
            <p style="font-size:18px; color:green; text-align:center;">谢谢参与!<br /><br />
                <asp:Button ID="Button2" runat="server" Text="再来一次" οnclick="Button2_Click" /></p>
            </asp:View>
        </asp:MultiView>
    </div>
    </form>
</body>
</html>



.aspx.cs代码如下:

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

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

        
    }
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string s_havePhone = rbl_1.SelectedValue;

        switch (s_havePhone) { 
            case "0": //没有手机
                mv1.SetActiveView(V_no);
                break;

            case "1": //有手机
                mv1.SetActiveView(V_Q2);
                break;
        }

    }
    protected void RadioButtonList1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        mv1.SetActiveView(V_DONE);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        mv1.SetActiveView(V_Q2);
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("2_Multiview.aspx");

        //请自己验证为何不用SetActiveView实现
        //mv1.SetActiveView(V_Q1);
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        mv1.SetActiveView(V_DONE);
    }
}



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值