I have a set of tabs (menu items) and a multiview nested within a formview. I want to be able to change view dependent on which menu item (tab) has been selected. Outside of formview I could go :
multiview1.activeViewIndex = 1 (for a menu item click event)
I would have expected to have been able to write the following for a menu item click event within a formview, but no events fire.
formview1.findcontrol("multiview1").activeviewinde x = 1
Can anybody help please. I am new to asp .net so I would appreciate it being kept as simple as possible. Thanks in advance. Code:
Expand|Select|Wrap|Line Numbers
- <%@ Page Trace="true" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <%@ Import Namespace="System.Web.UI.WebControls" %> <%@ Register assembly="AjaxControlToolkit"
- namespace="AjaxControlToolkit" tagprefix="asp" %> <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
- “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <Script Runat="Server">
- Sub Page_Load
- If not ispostback then
- Dim IDtransfer as string
- Dim RetPersSQL as string
- Dim idInt as integer
- Dim MenuTwo as control
- Dim MenuOne as control
- idtransfer = Convert.ToString(Request.QueryString("Id"))
- lbltransfer.text = idtransfer
- idInt = convert.toint32(idtransfer)
- Dim parameter1 As New System.Web.UI.WebControls.Parameter("Id", Data.DbType.Int32)
- parameter1.DefaultValue = idInt
- SQLReturnPerson.SelectParameters.Add(parameter1)
- menutwo = findcontrol("frmClientData").FindControl("menu2")
- Menutwo.visible="false"
- MenuOne = findcontrol("frmClientData").FindControl("menu1")
- MenuOne.visible="true"
- End if
- End Sub
- Public Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)
- Dim ActiveTab as integer
- Activetab = Int32.Parse(e.Item.Value)
- Dim MV1 as multiview
- MV1 = findcontrol("frmClientData").FindControl("multiview1")
- MV1.ActiveViewIndex = Activetab
- End sub
- Public Sub Menu2_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)
- Dim ActiveTab as integer
- Activetab = Int32.Parse(e.Item.Value)
- Dim MV1 as multiview
- MV1 = findcontrol("frmClientData").FindControl("multiview1")
- MV1.ActiveViewIndex = Activetab
- End sub
- </Script> <html> <head runat="Server"><title>Person Details</title> <style type="text/css">
- html {
- background-color:silver;
- }
- .tabs
- {
- position:relative; top:1px; left:1px;
- }
- .tab {
- border:solid 1px black; background-color:red; padding:2px
- 10px;
- }
- .selectedTab
- {
- background-color:white; border-bottom:solid 1px white;
- }
- </style> </head> <body> <form runat="Server"> <asp:SqlDataSource ID="SQLReturnPerson" runat="server"
- ConnectionString="<%$ ConnectionStrings:ViewPointConnectionString %>"
- SelectCommand="SELECT * FROM [Person] WHERE [Id]=@Id"> </asp:SqlDataSource> <br> <asp:FormView
- id="frmClientData"
- DataSourceID="SQLReturnPerson"
- DataKeyNames="Id"
- AllowPaging="false"
- runat="Server" > <ItemTemplate> <h1><%# Eval(“Id") %></h1><br> <%# Eval(“Client_forename") %> <%# Eval(“initials") %> <br> <br> <br> <div> <asp:Menu id="Menu1" Orientation="Horizontal" CssClass="tabs"
- Runat="server"> <staticmenuitemstyle backcolor="LightBlue"
- forecolor="Black"
- borderstyle="Solid"
- borderwidth="1"
- bordercolor="Black"
- itemspacing="10"
- horizontalpadding="40" /> <StaticSelectedStyle backcolor="White" borderstyle="Solid"
- bordercolor="Black"
- borderwidth="1" /> <Items> <asp:MenuItem Text="Tab 1" Value="0" Selected="true" /> <asp:MenuItem Text="Tab 2" Value="1" /> <asp:MenuItem Text="Tab 3" Value="2" /> </Items> </asp:Menu> <asp:Menu id="Menu2" Orientation="Horizontal" CssClass="tabs"
- Runat="server"> <staticmenuitemstyle backcolor="LightBlue"
- forecolor="Black"
- borderstyle="Solid"
- borderwidth="5"
- bordercolor="Black"
- itemspacing="10"
- horizontalpadding="40" /> <StaticSelectedStyle backcolor="White" borderstyle="Solid"
- bordercolor="Black"
- borderwidth="1" /> <Items> <asp:MenuItem Text="Tab 4" Value="0" Selected="true" /> <asp:MenuItem Text="Tab 5" Value="1" /> <asp:MenuItem Text="Tab 6" Value="2" /> </Items> </asp:Menu> </div> <div class="tabContents"> <asp:MultiView id="MultiView1" ActiveViewIndex="0" Runat="server"> <asp:View ID="View1" runat="server"> <br>This is the first view 1
- <br> <br> <h1><%# Eval(“Id") %></h1><br> <%# Eval(“Client_forename") %> <%# Eval(“initials") %> </asp:View> <asp:View ID="View2" runat="server"> <br>This is the second view 2
- <br> <h1><%# Eval(“Id") %></h1><br> <%# Eval(“Client_forename") %> <%# Eval(“initials") %> </asp:View> <asp:View ID="View3" runat="server"> <br>This is the third view 3
- </asp:View> </asp:MultiView> </div> <br> </ItemTemplate> </asp:FormView> <div> <asp:Label
- ID="lbltransfer"
- ForeColor="Red"
- Font-Bold="True"
- Runat="Server" /> </div> </form> </body> </html>