Reputation: 3568
Why can't I binding value to the dropdownlist? It always return message: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Name'.
I have a dropdownlist:
<asp:DropDownList ID="Parameter_Dropdownlist" runat="server">
</asp:DropDownList>
Then on code-behind:
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()
How can I bind the value to the dropdownlist? Please help. Thank you very much.
Upvotes: 0
Views: 695
Reputation: 5604
Try this, adding example :-
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()
Upvotes: 1