Web版的Tabcontrol控件的製作過程

先看運行後的結果吧:

1.選擇登錄記錄

2.選擇第二個選項卡

主要涉及的控件有:MultiView和一個Menu控件

主要代碼:

前臺:

  1. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TabControl.ascx.cs" Inherits="Tabcontrol.UserControl.TabControl" %> 
  2. <p> 
  3.    <asp:Menu 
  4.         ID="Menu1" 
  5.         Width="220px" 
  6.         runat="server" 
  7.         Orientation="Horizontal" 
  8.         StaticEnableDefaultPopOutImage="False" 
  9.         OnMenuItemClick="Menu1_MenuItemClick" BackColor="#E3EAEB" 
  10.     BorderStyle="Groove" BorderWidth="1px" DynamicHorizontalOffset="2" 
  11.     Font-Bold="False" Font-Names="Verdana" Font-Size="1em" Font-Underline="True" 
  12.     ForeColor="#666666" Height="24px" IncludeStyleBlock="False" PathSeparator="\" 
  13.     RenderingMode="Table" StaticSubMenuIndent="10px" > 
  14.        <DynamicHoverStyle BackColor="#666666" ForeColor="White" /> 
  15.        <DynamicMenuItemStyle BorderStyle="Double" BorderWidth="1px" 
  16.            HorizontalPadding="5px" VerticalPadding="2px" /> 
  17.        <DynamicMenuStyle BackColor="#E3EAEB" /> 
  18.        <DynamicSelectedStyle BackColor="#1C5E55" /> 
  19.        <DynamicItemTemplate> 
  20.            <%# Eval("Text") %> 
  21.        </DynamicItemTemplate> 
  22.     <Items> 
  23.         <asp:MenuItem 
  24.                       Text="   登錄記錄" Value="0" PopOutImageUrl="~/p_w_picpath/sb_more.png" 
  25.             Selected="True"   ></asp:MenuItem> 
  26.         <asp:MenuItem 
  27.                       Text="   用戶信息" Value="1" 
  28.             PopOutImageUrl="~/p_w_picpath/templatemo_more.png"></asp:MenuItem> 
  29.         <asp:MenuItem ImageUrl=" " 
  30.                       Text="   角色信息" Value="2" 
  31.             PopOutImageUrl="~/p_w_picpath/templatemo_more.png"></asp:MenuItem> 
  32.     </Items> 
  33.        <StaticHoverStyle BackColor="#666666" ForeColor="White" /> 
  34.        <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" /> 
  35.        <StaticSelectedStyle BackColor="#666666" BorderStyle="Double" 
  36.            ForeColor="#CCFFCC" /> 
  37. </asp:Menu> 
  38. <asp:MultiView 
  39.     ID="MultiView1" 
  40.     runat="server" 
  41.     ActiveViewIndex="0"  > 
  42.    <asp:View ID="Tab1" runat="server"  > 
  43.         <table width="600" height="400" cellpadding=0 cellspacing=0> 
  44.             <tr valign="top"> 
  45.                 <td class="TabArea" style="width: 600px"> 
  46.                     <br /> 
  47.                     <br /> 
  48.                     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
  49.                         AutoGenerateSelectButton="True" DataSourceID="SqlDataSource1"> 
  50.                         <Columns> 
  51.                             <asp:BoundField DataField="no" HeaderText="no" InsertVisible="False" 
  52.                                 ReadOnly="True" SortExpression="no" /> 
  53.                             <asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" 
  54.                                 SortExpression="id" /> 
  55.                             <asp:BoundField DataField="operator" HeaderText="operator" 
  56.                                 SortExpression="operator" /> 
  57.                             <asp:BoundField DataField="user_id" HeaderText="user_id" 
  58.                                 SortExpression="user_id" /> 
  59.                             <asp:BoundField DataField="last_login_time" HeaderText="last_login_time" 
  60.                                 SortExpression="last_login_time" /> 
  61.                             <asp:BoundField DataField="last_login_host_ip" HeaderText="last_login_host_ip" 
  62.                                 SortExpression="last_login_host_ip" /> 
  63.                             <asp:BoundField DataField="record_state" HeaderText="record_state" 
  64.                                 SortExpression="record_state" /> 
  65.                         </Columns> 
  66.                     </asp:GridView> 
  67.                     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
  68.                         ConnectionString="<%$ ConnectionStrings:QCS_DBConnectionString %>" 
  69.                         SelectCommand="SELECT * FROM [tb_log_user_login_system_operator]"> 
  70.                     </asp:SqlDataSource> 
  71.                 </td> 
  72.             </tr> 
  73.         </table> 
  74.      </asp:View> 
  75.     <asp:View ID="Tab2" runat="server"> 
  76.         <table width="600px" height="400px" cellpadding=0 cellspacing=0> 
  77.             <tr valign="top"> 
  78.                 <td class="TabArea" style="width: 600px"> 
  79.                 <br /> 
  80.                 <br /> 
  81.                     TAB VIEW 2 
  82.                     INSERT YOUR CONENT IN HERE 
  83.                     CHANGE SELECTED IMAGE URL AS NECESSARY 
  84.                 </td> 
  85.             </tr> 
  86.         </table> 
  87.     </asp:View> 
  88.     <asp:View ID="Tab3" runat="server"> 
  89.         <table width="600px" height="400px" cellpadding=0 cellspacing=0> 
  90.             <tr valign="top"> 
  91.                 <td class="TabArea" style="width: 600px"> 
  92.                 <br /> 
  93.                 <br /> 
  94.                   TAB VIEW 3 
  95.                   INSERT YOUR CONENT IN HERE 
  96.                   CHANGE SELECTED IMAGE URL AS NECESSARY 
  97.                 </td> 
  98.             </tr> 
  99.         </table> 
  100.     </asp:View> 
  101. </asp:MultiView> 
  102. </p> 


後臺的Menu1_MenuItemClick( object sender, MenuEventArgs e )的事件:

 

  1. protected void Menu1_MenuItemClick( object sender, MenuEventArgs e ) 
  2.         { 
  3.             MultiView1.ActiveViewIndex=Int32.Parse(e.Item.Value); 
  4.             for (int i=0; i<Menu1.Items.Count; i++) 
  5.             { 
  6.                 if (i==Int32.Parse(e.Item.Value)) 
  7.                 { 
  8.                     Menu1.Items[i].PopOutImageUrl="~/p_w_picpath/sb_more.png"
  9.                 } 
  10.                 else 
  11.                 { 
  12.                     Menu1.Items[i].PopOutImageUrl="~/p_w_picpath/templatemo_more.png"
  13.                 } 
  14.             } 
  15.         } 

然後運行就可以看到剛開始的結果了,謝謝參考!

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章