asp.net中MultiView和View

來源:互聯網
上載者:User

標籤: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!" onclick="Button1_Click" />                <asp:Button ID="Button3" runat="server" Text="NO,Thanks!"                     onclick="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="再來一次" onclick="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);    }}



asp.net中MultiView和View

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.