2011-08-06 77 views
0

我在菜單中使用multiview和asp菜單創建選項卡。 ,但切換到不同的標籤..我在標籤上的內容保持不變。 以下是代碼ASP.NET中的MultiView

<asp:Menu 
    ID="Menu1" 
    Width="168px" 
    runat="server" 
    Orientation="Horizontal" 
    StaticEnableDefaultPopOutImage="False" 
    OnMenuItemClick="Menu1_MenuItemClick"> 
    <Items> 
     <asp:MenuItem Text="TAB1" Value="0"></asp:MenuItem> 
     <asp:MenuItem Text="TAB2" Value="1"></asp:MenuItem> 
     <asp:MenuItem Text="TAB3" Value="2"></asp:MenuItem> 
    </Items> 
</asp:Menu> 
<asp:MultiView 
    ID="MultiView1" 
    runat="server" 
    ActiveViewIndex="0" > 
    <asp:View ID="tab1" runat="server" > 
     <table width="200" height="100" cellpadding=0 cellspacing=0> 
      <tr valign="top"> 
       <td class="TabArea" style="width: 600px"> 
        <br /> 
        <br /> 
        TAB VIEW 1 
        INSERT YOUR CONENT IN HERE 
        CHANGE SELECTED IMAGE URL AS NECESSARY 
       </td> 
      </tr> 
     </table> 
    </asp:View> 
    <asp:View ID="tab2" runat="server"> 
     <table width="200px" height="100px" cellpadding=0 cellspacing=0> 
      <tr valign="top"> 
       <td class="TabArea" style="width: 600px"> 
        <br /> 
        <br /> 
        TAB VIEW 2 
        INSERT YOUR CONENT IN HERE 
        CHANGE SELECTED IMAGE URL AS NECESSARY 
       </td> 
      </tr> 
     </table> 
    </asp:View> 
    <asp:View ID="tab3" runat="server"> 
     <table width="200px" height="100px" cellpadding=0 cellspacing=0> 
      <tr valign="top"> 
       <td class="TabArea" style="width: 600px"> 
        <br /> 
        <br /> 
        TAB VIEW 3 
        INSERT YOUR CONENT IN HERE 
        CHANGE SELECTED IMAGE URL AS NECESSARY 
       </td> 
      </tr> 
     </table> 
    </asp:View> 
</asp:MultiView> 

通過點擊不同的標籤我的內容仍然顯示第一個選項卡中的任何想法,爲什麼。

你幫助將不勝感激

回答

4

我相信你需要處理的代碼隱藏的OnMenuItemClick

protected void Menu1_MenuItemClick(object sender, MenuItemEventArgs e) 
{ 

    string menuTab = e.MenuItem.Value; 

    switch (menuTab) 
    { 
     case "0": 
      MultiView1.SetActiveView(tab1); 
      break; 
     case "1": 
      MultiView1.SetActiveView(tab2); 
      break; 
     case "2": 
      MultiView1.SetActiveView(tabe); 
      break; 
     default: 
      break; 
    } 
} 
+0

由於它的工作... – deepti

+1

歡迎你 - 高興能夠幫助。快樂的編碼! – Tim

+1

@Tim我相信應該是C#的一個'switch'而不是select。 – JoJo

1
 protected void menuTabs_MenuItemClick(object sender, MenuEventArgs e) 
    { 
     multiTabs.ActiveViewIndex = Int32.Parse(menuTabs.SelectedValue); 
     if (menuTabs.Items[0].Selected == true) 
     { 

      menuTabs.Items[0].ImageUrl = "~/Images/wit1_over.png"; 
      menuTabs.Items[1].ImageUrl = "~/Images/wit2.png"; 
     } 

     if (menuTabs.Items[1].Selected == true) 
     { 
      menuTabs.Items[1].ImageUrl = "~/Images/wit2_over.png"; 
      menuTabs.Items[0].ImageUrl = "~/Images/wit1.png"; 

     } 
    } 
    **//design code** 
     <asp:Menu ID="menuTabs" CssClass="menuTabs" StaticMenuItemStyle-CssClass="tab" StaticSelectedStyle-CssClass="selectedTab" 
      OnMenuItemClick="menuTabs_MenuItemClick" runat="server" Orientation="Horizontal" 
      BackColor="#f4f4f4" BorderStyle="None" class="img-swap1"> 
      <StaticSelectedStyle CssClass="selectedTab"></StaticSelectedStyle> 
      <StaticMenuItemStyle CssClass="tab"></StaticMenuItemStyle> 
      <Items> 
       <asp:MenuItem Text="" Value="0" Selected="true" ImageUrl="Images/wit1_over.png" /> 
       <asp:MenuItem Text="" Value="1" ImageUrl="Images/wit2.png" /> 
      </Items> 
     </asp:Menu> 


     <asp:MultiView ID="multiTabs" ActiveViewIndex="0" runat="server"> 
      <asp:View ID="view1" runat="server"> 
       </asp:View> 
      <asp:View ID="view2" runat="server"> 
       </asp:View> 
     </asp:MultiView>