开发者

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.Ite开发者_开发百科m.FindControl("selCurrentManuf"), DropDownList).Text

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


    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


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 )


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜