2011-10-06 63 views
-1

我有一個下拉列表我想在後面的代碼中使用一個SQL中的ID,但我得到錯誤...'selCurrentManuf'未被聲明。它可能是無法訪問,由於其保護水平

未聲明。由於其保護級別,它可能無法訪問。

<asp:DropDownList 
    selectedvalue='<%#Container.DataItem("manufidcurrent")%>' 
    ID="selCurrentManuf" 
    Runat="Server" 
    DataTextField="Desc" 
    DataValueField="manufid" 
    DataSource="<%# GetCurrentManuf() %>" 
    autopostback="true" 
    OnSelectedIndexChanged="selCurrentManuf_SelectedIndexChanged" ></asp:DropDownList> 

在後面的代碼我有一個功能,試圖用所選擇的選項...

Function GetCurrentModel() As DataSet 
Dim mySession = System.Web.HttpContext.Current.Session 
Dim myQuery As String = "SELECT * FROM model where id = " + selCurrentManuf.SelectedItem.Value 
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, "model") 
Dim dr As DataRow = myDataset.Tables(0).NewRow  
myDataset.Tables(0).Rows.Add(dr)  
GetCurrentModel = myDataset    
End Function 
+0

*** ***沒有聲明什麼...? –

+0

這對於SQL注入已經成熟,您應該考慮使用參數化查詢。 – CAbbott

+0

[dropdownlist未被聲明可能重複。它可能無法訪問,由於其保護級別](http://stackoverflow.com/questions/7678387/dropdownlist-is-not-declared-it-may-be-inaccessible-due-to-its-protection-level) –

回答

0

有時designer.cs文件被搞砸了。您可以手動將DropDown添加到designer.cs文件,或者再次將下拉菜單粘貼到標記中可能會改正問題。

要在designer.cs文件手動聲明下拉:

/// <summary> 
/// selCurrentManuf control. 
/// </summary> 
/// <remarks> 
/// Auto-generated field. 
/// To modify move field declaration from designer file to code-behind file. 
/// </remarks> 
protected global::System.Web.UI.WebControls.DropDownList selCurrentManuf; 
+0

這個文件在哪裏? – Beginner

+0

轉到解決方案資源管理器並展開ASPX文件。 –

+0

這個應用程序在Web服務器上運行我沒有它在vs – Beginner

相關問題