I am attempting to populate a dropdownlist in a web page. When I run it, the list displays "System.Data.DataRowView" instead of my data. It displays this for each row I have in the table.
Here is the code I am using.
mports System.Data
Imports System.Data.Common
Imports Microsoft.Data.Odbc
Public Class WebForm1
Inherits System.Web.UI.Page
Dim myConnStr As String = "DSN=CedarHill_Disc;UID=edpdisc;PWD=mallard;"
Dim objConn As New OdbcConnection(myConnStr)
Dim objCmd As New OdbcCommand()
Dim objDA As New OdbcDataAdapter()
Dim dvw As DataView
Dim ds As New DataSet()
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Dim strSQL As String
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
strSQL = "SELECT * FROM DI_C164_Disciplinary_Action_Codes"
objDA = New OdbcDataAdapter(strSQL, objConn)
objDA.Fill(ds, "D_A_C"
dvw = ds.Tables("D_A_C".DefaultView
DropDownList1.DataSource = dvw
DropDownList1.DataBind()
DropDownList1.DataValueField = "Code"
DropDownList1.DataTextField = "Description"
DataGrid1.DataSource = dvw
DataGrid1.DataBind()
End If
End Sub
End Class
Here is the code I am using.
mports System.Data
Imports System.Data.Common
Imports Microsoft.Data.Odbc
Public Class WebForm1
Inherits System.Web.UI.Page
Dim myConnStr As String = "DSN=CedarHill_Disc;UID=edpdisc;PWD=mallard;"
Dim objConn As New OdbcConnection(myConnStr)
Dim objCmd As New OdbcCommand()
Dim objDA As New OdbcDataAdapter()
Dim dvw As DataView
Dim ds As New DataSet()
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Dim strSQL As String
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
strSQL = "SELECT * FROM DI_C164_Disciplinary_Action_Codes"
objDA = New OdbcDataAdapter(strSQL, objConn)
objDA.Fill(ds, "D_A_C"
dvw = ds.Tables("D_A_C".DefaultView
DropDownList1.DataSource = dvw
DropDownList1.DataBind()
DropDownList1.DataValueField = "Code"
DropDownList1.DataTextField = "Description"
DataGrid1.DataSource = dvw
DataGrid1.DataBind()
End If
End Sub
End Class