未声明下拉列表。由于其保护级别,它可能无法访问

时间:2011-10-06 17:48:11

标签: asp.net vb.net

从注释掉的代码中可以看出,我试图让模型下拉列表受到+ selCurrentManuf.Text的影响。

我收到此错误

  

'selCurrentManuf'未声明。由于其保护级别,它可能无法访问。

如何解决这个问题?

我可以像这样访问页面另一部分的下拉菜单。

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

但是在我尝试使用的函数中,selCurrentManuf无法访问e

3 个答案:

答案 0 :(得分:1)

右键单击.aspx页面,然后选择“转换为Web应用程序”命令。

然后你就可以写:

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

答案 1 :(得分:1)

    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

答案 2 :(得分:0)

我假设您的函数位于App_Code或其他dll中的类中,而不是页面后面的代码。

若是,请改为:

我假设你的asp页面代码背后有这样的东西:

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

将您的GetCurrentModel代码更改为:

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