ASP.NET 用MultiView和View实现选项卡效果

来源:互联网 发布:js鞋子是什么牌子 编辑:程序博客网 时间:2024/06/08 06:23
标签: asp.netbuttonserverasp网络sql server
 11184人阅读 评论(5) 收藏 举报
 分类:

                     ASP.NET中的MultiView和View可以作为其他控件的容器,提供了一种可方便地显示信息的替换视图方式。通常情况下, MultiView和View搭配使用。我一般很少使用这两控件,本文讲讲用MultiView和View实现选项卡效果。贴上前台代码:

[html] view plaincopy
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication3._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>用MultiView和View实现选项卡效果</title>  
  7. </head>  
  8. <body>  
  9.     <form id="form1" runat="server">  
  10.     <div>  
  11.         <asp:Button ID="btnIntroduction" runat="server" BorderWidth="0" Text="公司简介" OnClick="btnIntroduction_Click" />  
  12.         <asp:Button ID="btnWelcome" runat="server" BorderWidth="0" Text="欢迎加盟" OnClick="btnIntroduction_Click" />  
  13.         <table style="border: 1px ridge #0000FF; width: 100%;">  
  14.             <tr valign="top">  
  15.                 <td style="width: 300; height: 250">  
  16.                     <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">  
  17.                         <asp:View ID="View1" runat="server">  
  18.                             <asp:Label ID="Label1" runat="server"></asp:Label>  
  19.                         </asp:View>  
  20.                         <asp:View ID="View2" runat="server">  
  21.                             <asp:Label ID="Label2" runat="server"></asp:Label>  
  22.                         </asp:View>  
  23.                     </asp:MultiView>  
  24.                 </td>  
  25.             </tr>  
  26.         </table>  
  27.     </div>  
  28.     </form>  
  29. </body>  
  30. </html>  
设计效果如下:


用两个Button(btnIntroduction、btnWelcome)作为切换Tab按钮,这两个Button按钮关联到同一个事件处理。其实用ImageButton来实现应该会更好看一点。

后台cs实现切换功能代码:

[csharp] view plaincopy
  1. using System;  
  2. using System.Collections;  
  3. using System.Configuration;  
  4. using System.Data;  
  5. using System.Linq;  
  6. using System.Web;  
  7. using System.Web.Security;  
  8. using System.Web.UI;  
  9. using System.Web.UI.HtmlControls;  
  10. using System.Web.UI.WebControls;  
  11. using System.Web.UI.WebControls.WebParts;  
  12. using System.Xml.Linq;  
  13.   
  14. namespace WebApplication3  
  15. {  
  16.     public partial class _Default : System.Web.UI.Page  
  17.     {  
  18.         protected void Page_Load(object sender, EventArgs e)  
  19.         {  
  20.             Label1.Text = @"本公司为一家集软件开发、传统网络开发以及无线网络开发的大型科技公司。公司自成立以来经过长期发展,取得了80多项国家专利!" + "\r\n" +  
  21. @"本公司为一家集软件开发、传统网络开发以及无线网络开发的大型科技公司。公司自成立以来经过长期发展,取得了80多项国家专利!" + "\r\n" +  
  22. @"本公司为一家集软件开发、传统网络开发以及无线网络开发的大型科技公司。公司自成立以来经过长期发展,取得了80多项国家专利!" + "\r\n" +  
  23. @"本公司为一家集软件开发、传统网络开发以及无线网络开发的大型科技公司。公司自成立以来经过长期发展,取得了80多项国家专利!";  
  24.             Label2.Text = @"欢迎有志之士加盟本公司!  
  25.         软件开发工程师  
  26.         要求:   
  27.         1、热爱软件行业;   
  28.         2、熟悉、net框架,能熟练使用C#和JavaScript进行编码;   
  29.         3、熟悉SQL Server等常用的数据库;   
  30.         4、有良好的编码规范习惯;   
  31.         5、做事认真负责,服从公司的工作安排;   
  32.         6、吃苦耐劳,敬业。 ";  
  33.         }  
  34.   
  35.         protected void btnIntroduction_Click(object sender, EventArgs e)  
  36.         {  
  37.             //获取被触发的Button对象  
  38.             Button b = (Button)sender;  
  39.             if (b.ID == "btnIntroduction")  
  40.             {  
  41.                 //激活View1  
  42.                 MultiView1.SetActiveView(View1);  
  43.             }  
  44.             else  
  45.             {  
  46.                 //激活View2  
  47.                 MultiView1.SetActiveView(View2);  
  48.             }  
  49.         }  
  50.     }  
  51. }  

浏览效果:


http://blog.csdn.net/chinajiyong/article/details/7577604
0 0
原创粉丝点击