MultiView 和 View 控件和制作出选项卡的效果,MultiView 控件是一组 View 控件的容器。使用它可定义一组 View 控件,其中每个 View 控件都包含子控件。
如果要切换视图,可以使用控件的ID或者View控件的索引值。在 MultiView 控件中,一次只能将一个 View 控件定义为活动视图。如果某个 View 控件定义为活动视图,它所包含的子控件则会呈现到客户端。可以使用 ActiveViewIndex 属性或SetActiveView 方法定义活动视图。如果 ActiveViewIndex 属性为空,则 MultiView 控件不向客户端呈现任何内容。如果活动视图设置为MultiView 控件中不存在的 View,则会在运行时引发 ArgumentOutOfRangeException。
一些常用的属性、方法:
ActiveViewIndex属性:用于获取或设置当前被激活显示的View控件的索引值。默认值为-1,表示没有View控件被激活。
SetActiveView方法:用于激活显示特定的View控件。
4个静态只读字段:若要允许用户在 MultiView 控件中的 View 控件之间进行导航,可将 LinkButton 或 Button 控件添加到每个 View 控件。若要利用 MultiView 控件对当前活动 View 进行自动更新,请将按钮或链接按钮的 CommandName 属性设置为与所需导航行为对应的命令名字段的值,这些命令名字段如下:PreviousViewCommandName、NextViewCommandName、SwitchViewByIDCommandName 或 SwitchViewByIndexCommandName。
ActiveViewChanged事件:当视图切换时被激发。
应用示例:
1
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2
3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml">
5
<head runat="server">
6
<title>示例8-5</title>
7
<link id="InstanceStyle" href="StyleSheet.css" type="text/css" rel="stylesheet" />
8
</head>
9
<body>
10
<form id="Form1" runat="server">
11
<div>
12
<fieldset style=" 400px">
13
<legend class="mainTitle">MultiView和View控件典型应用</legend>
14
<br />
15
<table id="Table1" height="95%" cellspacing="0" cellpadding="0" width="100%" border="0">
16
<tr>
17
<td>
18
<table id="TopTable" runat="server" cellspacing="0" cellpadding="0" width="100%"
19
border="0">
20
<tr style="height: 22px">
21
<td class="SelectedTopBorder" id="Cell1" align="center" width="60">
22
<asp:LinkButton ID="LBView1" runat="server" CssClass="TopTitle" OnClick="LBView1_Click">常规</asp:LinkButton>
23
</td>
24
<td class="SepBorder" width="2px">
25
</td>
26
<td class="TopBorder" id="Cell2" align="center" width="60">
27
<asp:LinkButton ID="LBView2" runat="server" CssClass="TopTitle" OnClick="LBView2_Click">硬件</asp:LinkButton>
28
</td>
29
<td class="SepBorder" width="2px">
30
</td>
31
<td class="TopBorder" id="Cell3" align="center" width="60">
32
<asp:LinkButton ID="LBView3" runat="server" CssClass="TopTitle" OnClick="LBView3_Click">高级</asp:LinkButton>
33
</td>
34
<td class="SepBorder">
35
</td>
36
</tr>
37
</table>
38
</td>
39
</tr>
40
<tr>
41
<td>
42
<table class="ContentBorder" cellspacing="0" cellpadding="0">
43
<tr>
44
<td valign="top">
45
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
46
<asp:View ID="View1" runat="server">
47
<img src="images/tab0.jpg" />
48
</asp:View>
49
<asp:View ID="View2" runat="server">
50
<img src="images/tab2.jpg" />
51
</asp:View>
52
<asp:View ID="View3" runat="server">
53
<img src="images/tab3.jpg" />
54
</asp:View>
55
</asp:MultiView>
56
</td>
57
</tr>
58
</table>
59
</td>
60
</tr>
61
</table>
62
</fieldset>
63
</div>
64
</form>
65
</body>
66
</html>

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

using System;

























































































































