Beginner
Beginner

Reputation: 29573

dropdownlist is not declared. It may be inaccessible due to its protection level

As you can see from the commented out code, I'm trying to get the model dropdown be affected by + selCurrentManuf.Text.

I get this error

'selCurrentManuf' is not declared. It may be inaccessible due to its protection level.

How can this be solved?

I can access the drop down in another part of the page like this..

Dim sc1_currentmanuf As String = CType(e.Item.FindControl("selCurrentManuf"), DropDownList).Text

However in the function i am trying to use selCurrentManuf does not have access to e

Upvotes: 0

Views: 4105

Answers (3)

Beginner
Beginner

Reputation: 29573

    Dim sc1_currentmanuf As String = CType(dlContacts.Items(0).FindControl("selCurrentManuf"), DropDownList).Text
    Dim myQuery As String = "SELECT * FROM c5_model where c5_manufid = " + sc1_currentmanuf

Upvotes: 2

Gilbert
Gilbert

Reputation: 36

I'm assuming your functions are inside a class in your App_Code or another dll and not on the code behind of the page.

If so do this instead:

I'm assuming you have something like this on your asp page code behind:

Protected Sub selCurrentManuf_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        GetCurrentModel(selCurrentManuf.Text)
End Sub

Change Your GetCurrentModel Code To:

Function GetCurrentModel(Byval c5_manuf as String) As DataSet
    Dim mySession = System.Web.HttpContext.Current.Session
    Dim myQuery As String = "SELECT * FROM c5_model " 'where c5_manuf = " + + c5_manuf 
    Dim myConnection As New MySqlConnection(mySession("localConn"))
    myConnection.Open()
    Dim myCommand As New MySqlCommand(myQuery, myConnection)
    Dim myDataAdapter = New MySqlDataAdapter(myCommand)
    Dim myDataset As New DataSet
    myDataAdapter.Fill(myDataset, "c5_model")
    Dim dr As DataRow = myDataset.Tables(0).NewRow       
    myDataset.Tables(0).Rows.Add(dr)      
    GetCurrentModel =  myDataset
    myConnection.Close()         
 End Function

Upvotes: 0

p.campbell
p.campbell

Reputation: 100607

Right click on your .aspx page, and select the command Convert To Web Application.

Then you'll be able to write:

  Dim myQuery As String = 
    String.Format("SELECT * FROM c5_model WHERE c5_manuf = '{0}'", 
                  selCurrentManuf.SelectedItem.Text )

Upvotes: 1

Related Questions