I have a multiview inside a form view. The multiview active index is based on a dropdownlist selection, I found out that I need to put this line somewhere:

<script runat="server">
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) 
MultiView2.ActiveViewIndex = DropDownList1.SelectedValue
End Sub
</script>

My page has a masterpage, so the main page looks like this:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" title="test" %>

<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="Server">

<asp:FormView ID="FormView1" runat="server" DataSourceID="sdsDetail" DefaultMode="Edit">

<EditItemTemplate>

<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("Active") %>' AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

<asp:ListItem Value=""></asp:ListItem>

<asp:ListItem Value="A">Active Employee </asp:ListItem>

<asp:ListItem Value="R">Retired</asp:ListItem>

</asp:DropDownList>

<asp:MultiView ID="MultiView2" runat="server">
                    <asp:View ID="View1" runat="server">
                        <asp:ListBox ID="ListBox1" runat="server" DataSourceID="odsDept" DataTextField="Dept_name"
                            DataValueField="Dept_name" SelectedValue='<%# bind("Dept") %>' Width="232px">
                        </asp:ListBox><asp:ObjectDataSource ID="odsDept" runat="server" OldValuesParameterFormatString="original_{0}"
                            SelectMethod="GetDept" TypeName="TableAdapters.A_TableAdapter"></asp:ObjectDataSource>
                    </asp:View>
                    <asp:View ID="View2" runat="server">
                        <asp:ListBox ID="ListBox2" runat="server" DataSourceID="odsB" DataTextField="Group_Name"
                            DataValueField="Group_Name" SelectedValue='<%# bind("Dept") %>' Width="232px">
                        </asp:ListBox><asp:ObjectDataSource ID="odsB" runat="server" OldValuesParameterFormatString="original_{0}"
                            SelectMethod="GetGroup" TypeName="TableAdapters.B_TableAdapter"></asp:ObjectDataSource>
                    </asp:View>
                </asp:MultiView>
</EditItemTemplate>
</asp:FormView>
</asp:Content>

I have had people suggesting me to put it in the vb file like this:

Partial Class list_pages_Details
    Inherits System.Web.UI.Page

    'Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    '    dim MultiView mv
    '    dim DropDownList ddl

    '    mv = (MultiView)FormView1.FindControl("MultiView2")
    '    ddl = (DropDownList)FormView1.FindControl("DropDownList1")

    '    mv.ActiveViewIndex = ddl.SelectedValue
    'End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
End Class

I tried putting the sub inside FormView, inside Edit Template, inside master file....
Anywhere I put it, same error:
name mv not declared....

Please help me, where can I put it, or how can I achieve what I need to do?

Thank you for your time!!!

you need to put that code in your test.aspx.vb file.

I did, and it complaints
1. end of statement expected.
2. mv, ddl is not declared...

any suggestions? thank you.

my VB file looks like:

Partial Class test
    Inherits System.Web.UI.Page
    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            dim mv as MultiView = (MultiView)FormView1.FindControl("MultiView2")
            dim ddl as DropDownList = (DropDownList)FormView1.FindControl("DropDownList1")
        mv.ActiveViewIndex = ddl.SelectedValue
    End Sub
End Class

I got it fixed, thank you!

looks like:

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim mv As MultiView = FormView1.FindControl("MultiView2")
        Dim ddl As DropDownList = FormView1.FindControl("DropDownList1")
        mv.ActiveViewIndex = ddl.SelectedValue
    End Sub
This article has been dead for over six months. Start a new discussion instead.