VS.NET(C#)-4.4_MultiView和View控件应用案例二
MultiView和View控件应用案例二
MultiView和View搭配实现导航功能,用Button(下一个,前一个) 切换4个不同视图。通过RadioButtonList控件显示活动视图变化的顺序。
重点用法:活动视图发生变化时,MultiView控件将触发ActiveViewChanged事件,与此同时,view视图将触发Activate事件。
UI设计视图
UI代码视图
<%@ PageLanguage="C#"AutoEventWireup="true"CodeFile="MultiView.aspx.cs"Inherits="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>
<h1>
MultiView & View Controls</h1>
<br />
<asp:RadioButtonList ID="rblView" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="-1">Nothing</asp:ListItem>
<asp:ListItem Selected="True" Value="0">First</asp:ListItem>
<asp:ListItem Value="1">Second</asp:ListItem>
<asp:ListItem Value="2">Third</asp:ListItem>
<asp:ListItem Value="3">Last</asp:ListItem>
</asp:RadioButtonList>
<br />
Current Index :<asp:Label ID="lblCurrentIndex"runat="server"Text="Label"></asp:Label>
<br />
<asp:MultiView ID="MultiView1" runat="server" OnActiveViewChanged="MultiView1_ActiveViewChanged"
ActiveViewIndex="0">
<asp:View ID="vwFirst" runat="server" OnActivate="vwFirst_Activate">
<h2>
First View</h2>
<asp:TextBox ID="txtFirstView" runat="server"></asp:TextBox>
<asp:Button ID="btnNext1" runat="server" Text="Go To Next" CommandName="NextView" />
<asp:Button ID="btnLast1" runat="server" Text="Go To Last" CommandArgument="vwLast"
CommandName="SwitchViewByID"/>
</asp:View>
<asp:View ID="vwSecond" runat="server" OnActivate="vwSecond_Activate">
<h2>
Second View</h2>
<asp:TextBox ID="txtSecondView" runat="server"></asp:TextBox>
<asp:Button ID="btnNext2" runat="server" Text="Go To Next" CommandName="NextView" />
<asp:Button ID="btnPrevious2" runat="server" Text="Go to Previous" CommandName="PrevView" />
</asp:View>
<asp:View ID="vwThird" runat="server" OnActivate="vwThird_Activate">
<h2>
Third View</h2>
<br />
<asp:Button ID="btnNext3" runat="server" Text="Go To Next" CommandName="NextView" />
<asp:Button ID="btnPreviou3" runat="server" Text="Go to Previous" CommandName="PrevView" />
</asp:View>
<asp:View ID="vwLast" runat="server" OnActivate="vwLast_Activate">
<h2>
Last View</h2>
<br />
<asp:Button ID="btnPrevious4" runat="server" Text="Go To Previous" CommandName="PrevView" />
<asp:Button ID="btnFirst" runat="server" Text="Go To First" CommandName="SwitchViewByIndex"
CommandArgument="0" />
</asp:View>
</asp:MultiView>
<br />
<br />
FirstBox:<asp:Label ID="lblFirstTextBox"runat="server"Text=""></asp:Label>
<br />
<br />
SecondBox:<asp:Label ID="lblSecondTextBox" runat="server" Text=""></asp:Label>
<br />
<br />
View Avtive History:<asp:Label ID="lblActivation"runat="server"Text=""></asp:Label>
</div>
</form>
</body>
</html>
CS代码视图
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
public partial class MultiView : System.Web.UI.Page
{
protected void Page_Load(objectsender, EventArgs e)
{
}
protected void MultiView1_ActiveViewChanged(object sender, EventArgse)
{
lblFirstTextBox.Text =txtFirstView.Text;
lblSecondTextBox.Text =txtSecondView.Text;
rblView.SelectedIndex =MultiView1.ActiveViewIndex + 1;
}
protected void vwFirst_Activate(objectsender, EventArgs e)
{
Stringstr = lblActivation.Text;
Viewv = (View)sender;
str += "View" + v.ID + " actived<br/>";
lblActivation.Text = str;
}
protected void vwSecond_Activate(objectsender, EventArgs e)
{
Stringstr = lblActivation.Text;
Viewv = (View)sender;
str += "View" + v.ID + " actived<br/>";
lblActivation.Text = str;
}
protected void vwThird_Activate(objectsender, EventArgs e)
{
Stringstr = lblActivation.Text;
Viewv = (View)sender;
str += "View" + v.ID + " actived<br/>";
lblActivation.Text = str;
}
protected void vwLast_Activate(objectsender, EventArgs e)
{
Stringstr = lblActivation.Text;
Viewv = (View)sender;
str += "View" + v.ID + " actived<br/>";
lblActivation.Text = str;
}
}
UI运行时图
单击下一步(视图二)
单击下一步(视图三)
单击下一步(视图四)