博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

VS2005 里面用Menu + MuliView模仿Tab标签

Posted on 2008-07-29 09:55  LonelyStar  阅读(411)  评论(0编辑  收藏  举报

aspx页面代码

 

 1<form id="form1" runat="server">
 2    <div>
 3        <asp:Menu ID="Menu1" runat="server" OnMenuItemClick="Menu1_MenuItemClick" Orientation="Horizontal" StaticEnableDefaultPopOutImage="False">
 4            <Items>
 5                <asp:MenuItem Text="<div style='width:150px; height:21px; background-image:url(Images/select.gif); text-align:center;'>Go</div>" Value="0">
 6                </asp:MenuItem>
 7               <asp:MenuItem Text="<div style='width:150px; height:21px; background-image:url(Images/unselect.gif); text-align:center;'>Return</div>"  Value="1">
 8                </asp:MenuItem> 
 9            </Items>
10        </asp:Menu>
11        
12        <asp:MultiView ID="MultiView1" runat="server">
13            <asp:View ID="View1" runat="server">
14                view 1<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></asp:View>
15            <asp:View ID="View2" runat="server">
16                view 2<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></asp:View>
17        </asp:MultiView>
18       <br />        
19        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
20    </form>

 

cs代码:

 

 1protected void Page_Load(object sender, EventArgs e)
 2        {
 3            this.MultiView1.ActiveViewIndex = 0;
 4        }

 5
 6        protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
 7        {
 8            int index = int.Parse(e.Item.Value);
 9
10            this.MultiView1.ActiveViewIndex = index;
11
12            for (int i = 0; i < this.Menu1.Items.Count; i++)
13            {
14                if (i == int.Parse(e.Item.Value))
15                {
16                    this.Menu1.Items[i].Text = this.Menu1.Items[i].Text.Replace("/unselect.gif""/select.gif");
17                }

18                else
19                {
20                    //this.Menu1.Items[i].ImageUrl = "Images/unselect.gif";
21                    this.Menu1.Items[i].Text = this.Menu1.Items[i].Text.Replace("/select.gif""/unselect.gif");
22                }

23            }

24        }

25
26        protected void Button1_Click(object sender, EventArgs e)
27        {
28            Response.Write(string.Format("value of view1 is : {0}<br>value of view 2 is {1}"this.TextBox1.Text, this.TextBox2.Text));
29        }

 

这里用的是Div里面显示文字,背景用图片显示,也可以直接用图片显示的

下载源码