我有一个下拉列表我试图在后面的代码中使用sql中的id但我得到错误...
未声明。由于其保护级别,它可能无法访问。
<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)
有时designer.cs
文件被搞砸了。您可以手动将DropDown添加到designer.cs
文件,或者再次将下拉列表粘贴到标记中可以解决问题。
在designer.cs
文件中手动声明DropDown:
/// <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;