Error with SelectedIndexChanged using CascadingDropDown in ASP.NET, VB and VS 2012

Discussion in '.NET' started by Deedv76, Aug 26, 2015.

  1. Deedv76

    Deedv76

    Joined:
    Aug 26, 2015
    Messages:
    1
    Likes Received:
    0
    Hi all,

    I receive an error "ddlCountry_SelectedIndexChanged is not a member of ASP.dll_vb_asp" and cannot load the page in the browser, when attempting to create Cascading Drop Downs in ASP.NET using Visual Studio 2012 and Visual Basic. Here is my code, if any one can help to figure out what is wrong in my code causing me this error. If I can get this sample working, I can get working on a project I need done.

    My DDL_VB.aspx page:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
    <title>Ajax bind cascading country-state-city dropdownlist without
    page refresh example in asp.net</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <div>
    <h4>
    Ajax bind cascading country-state-city dropdownlist without page refresh</h4>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <table>
    <tr>
    <td>
    Select Country:
    <asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="True"
    OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged" DataSourceID="SqlDataSourceCountry" DataTextField="CountryName" DataValueField="CountryName">
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSourceCountry" runat="server" ConnectionString="<%$ ConnectionStrings:CustomToolsDBConnectionString %>" SelectCommand="SELECT [CountryName] FROM [Country] ORDER BY [CountryName]"></asp:SqlDataSource>
    </td>
    </tr>
    <tr>
    <td>
    Select State:
    <asp:DropDownList ID="ddlState" runat="server" AutoPostBack="True"
    OnSelectedIndexChanged="ddlState_SelectedIndexChanged" DataSourceID="SqlDataSourceState" DataTextField="StateName" DataValueField="StateName">
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSourceState" runat="server" ConnectionString="<%$ ConnectionStrings:CustomToolsDBConnectionString %>" SelectCommand="SELECT [StateName] FROM [State]"></asp:SqlDataSource>
    </td>
    </tr>
    <tr>
    <td>
    Select City:
    <asp:DropDownList ID="ddlCity" runat="server" DataSourceID="SqlDataSourceCity" DataTextField="CityName" DataValueField="CityName">
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSourceCity" runat="server" ConnectionString="<%$ ConnectionStrings:CustomToolsDBConnectionString %>" SelectCommand="SELECT [CityName] FROM [City]"></asp:SqlDataSource>
    </td>
    </tr>
    </table>
    <asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="UpdatePanel1"
    runat="server">
    <ProgressTemplate>
    <div id="ajaxloader">
    Loading..</div>
    </ProgressTemplate>
    </asp:UpdateProgress>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlCountry" EventName="SelectedIndexChanged" />
    <asp:AsyncPostBackTrigger ControlID="ddlState" EventName="SelectedIndexChanged" />
    </Triggers>
    </asp:UpdatePanel>
    </div>
    </form>
    </body>
    </html>




    My DDL_VB.aspx.vb page:

    Imports System.Data.SqlClient
    Imports System.Data

    Partial Class DDL_VB
    Inherits System.Web.UI.Page
    'specify your connection string here..
    Public Shared strConn As String =
    "Data Source=c3digpssql2;Integrated Security=true;Initial Catalog=CustomToolsDB"

    Private Property ddlState As Object

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
    BindCountryList()
    End If
    End Sub
    'bind countries to country dropdownlist
    Private Sub BindCountryList()
    Try
    Using sqlConn As New SqlConnection(strConn)
    Using sqlCmd As New SqlCommand()
    sqlCmd.CommandText = "SELECT CountryId,CountryName FROM Country"
    sqlCmd.Connection = sqlConn
    sqlConn.Open()
    Dim da As New SqlDataAdapter(sqlCmd)
    Dim dt As New DataTable()
    da.Fill(dt)
    ddlCountry.DataSource = dt
    ddlCountry.DataValueField = "CountryId"
    ddlCountry.DataTextField = "CountryName"
    ddlCountry.DataBind()
    sqlConn.Close()

    'Adding "Please select country" option in dropdownlist
    ddlCountry.Items.Insert(0, New ListItem("Please select country", "0"))

    'Adding initially value to "state" and "city" dropdownlist
    ddlState.Items.Insert(0, New ListItem("Please select state", "0"))
    ddlCity.Items.Insert(0, New ListItem("Please select city", "0"))
    End Using
    End Using
    Catch
    End Try
    End Sub

    'bind states to state dropdownlist on country change event
    Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    Try
    Using sqlConn As New SqlConnection(strConn)
    Using sqlCmd As New SqlCommand()
    sqlCmd.CommandText = "SELECT StateId,StateName FROM State " &
    "WHERE CountryId=@CountryId"
    sqlCmd.Parameters.AddWithValue("@CountryId", ddlCountry.SelectedValue)
    sqlCmd.Connection = sqlConn
    sqlConn.Open()
    Dim da As New SqlDataAdapter(sqlCmd)
    Dim dt As New DataTable()
    da.Fill(dt)
    ddlState.DataSource = dt
    ddlState.DataValueField = "StateId"
    ddlState.DataTextField = "StateName"
    ddlState.DataBind()
    sqlConn.Close()

    'Adding "Please select state" option in dropdownlist
    ddlState.Items.Insert(0, New ListItem("Please select state", "0"))

    'also clear city dropdownlist because we are changing country
    ddlCity.Items.Clear()
    ddlCity.Items.Insert(0, New ListItem("Please select city", "0"))
    End Using
    End Using
    Catch
    End Try
    End Sub

    'bind cities to city dropdownlist on state change event
    Protected Sub ddlState_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    Try
    Using sqlConn As New SqlConnection(strConn)
    Using sqlCmd As New SqlCommand()
    sqlCmd.CommandText = "SELECT CityId,CityName FROM City " &
    "WHERE StateId=@StateId"
    sqlCmd.Parameters.AddWithValue("@StateId", ddlState.SelectedValue)
    sqlCmd.Connection = sqlConn
    sqlConn.Open()
    Dim da As New SqlDataAdapter(sqlCmd)
    Dim dt As New DataTable()
    da.Fill(dt)
    ddlCity.DataSource = dt
    ddlCity.DataValueField = "CityId"
    ddlCity.DataTextField = "CityName"
    ddlCity.DataBind()
    sqlConn.Close()

    'Adding "Please select city" option in dropdownlist
    ddlCity.Items.Insert(0, New ListItem("Please select city", "0"))
    End Using
    End Using
    Catch
    End Try
    End Sub

    Private Function ddlCountry() As Object
    Throw New NotImplementedException
    End Function

    Private Function ddlCity() As Object
    Throw New NotImplementedException
    End Function

    End Class

    Any help is appreciated!
     
    Deedv76, Aug 26, 2015
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mark4asp
    Replies:
    0
    Views:
    8,729
    mark4asp
    Mar 29, 2007
  2. Mauro SB.

    cascadingdropdown method error 500

    Mauro SB., Apr 18, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    7,671
    davenel@leneva.com
    Apr 23, 2007
  3. glenh
    Replies:
    0
    Views:
    521
    glenh
    Aug 19, 2007
  4. Med
    Replies:
    1
    Views:
    587
  5. wfsmith@gmail.com
    Replies:
    0
    Views:
    694
    wfsmith@gmail.com
    Mar 8, 2008
  6. MU
    Replies:
    0
    Views:
    532
  7. Vittorio Pavesi

    CascadingDropDown

    Vittorio Pavesi, May 26, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    212
    Vittorio Pavesi
    May 30, 2006
  8. hkaiser
    Replies:
    3
    Views:
    877
    Ebenezer
    Jan 13, 2012
Loading...