0

为什么我不能将值绑定到下拉列表?它总是返回消息:DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Name'.

我有一个下拉列表:

<asp:DropDownList ID="Parameter_Dropdownlist" runat="server">
</asp:DropDownList>   

然后在代码隐藏上:

If myCEConnection.State = ConnectionState.Closed Then
    Try
        myCEConnection.Open()
    Catch
        Return
    End Try
End If

Dim reader As SqlCeDataReader
Dim myCommand As SqlCeCommand = myCEConnection.CreateCommand()

myCommand.CommandText = "SELECT Name, Code FROM Room"
reader = myCommand.ExecuteReader()

DT.Load(reader)

DDL.DataSource = DT
DDL.DataTextField = DT.Columns("Name").ColumnName.ToString()
DDL.DataValueField = DT.Columns("Code").ColumnName.ToString()
DDL.DataBind()

myCEConnection.Close()

如何将值绑定到下拉列表?请帮忙。非常感谢。

4

1 回答 1

1

试试这个,添加示例:-

If myCEConnection.State = ConnectionState.Closed Then
   Try
      myCEConnection.Open()
  Catch
      Return
  End Try
End If

Dim reader As SqlCeDataReader
Dim myCommand As SqlCeCommand = myCEConnection.CreateCommand()

myCommand.CommandText = "SELECT Name, Code FROM Room"
reader = myCommand.ExecuteReader()

DT.Load(reader)

DDL.DataSource = DT
DDL.DataTextField = DT.Columns(0).ColumnName.ToString()
DDL.DataValueField = DT.Columns(1).ColumnName.ToString()
DDL.DataBind()

myCEConnection.Close()
于 2012-05-04T07:09:59.700 回答