Link to home
Start Free TrialLog in
Avatar of lnshop
lnshop

asked on

System.Data.DataRowView in DropDownList Box

I am having trouble populating my dropdown list box with data from a database.  The control code is below.  It is displaying System.Data.DataRowView 8 times which is the correct number of rows to return.  Can someone please advise what I have done wrong.  I am using windows XP and Foxpro 6.0  Thank you for your assistance.
<asp:DropDownList ID="ddlCasPolicyTypeOptions"  DataTextField="policy_typ" DataValueField="policy_typ" runat="server">
                            </asp:DropDownList>
VB 2005 Code 
Dim CasPolicyType As New OdbcCommand(strCasualtyPolicyType, connCasPolicyType)
            CasPolicyType.CommandText = "SELECT DISTINCT trim(cas_request.policy_typ) " & _
           "FROM cas_request " & _
           "where cas_request.Policy_typ<>"""" ORDER BY cas_Request.policy_typ ASC"
            Dim CasPolicyTypeDataAdapter As New Odbc.OdbcDataAdapter
            Dim CasPolicyTypeDataView As DataView
            Dim CasPolicyTypeDataSet As New DataSet
            CasPolicyTypeDataAdapter = New OdbcDataAdapter(strCasualtyPolicyType, connCasPolicyType)
            CasPolicyTypeDataAdapter.Fill(CasPolicyTypeDataSet, "cas_request")
            CasPolicyTypeDataView = CasPolicyTypeDataSet.Tables("cas_request").DefaultView
            ddlCasPolicyType.DataSource = CasPolicyTypeDataView
            ddlCasPolicyType.DataBind()

Open in new window

Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

You will also need to set the DataTextField and DataValueField properties of the DropDownList....

            ddlCasPolicyType.DataSource = CasPolicyTypeDataView
            ddlCasPolicyType.DataTextField = "policy_typ"
            ddlCasPolicyType.DataValueField = "policy_typ"
            ddlCasPolicyType.DataBind()

Wayne
Avatar of lnshop
lnshop

ASKER

This is the error message I am getting.  I have checked the table several times and there is a field named policy_typ.
'System.Data.DataRowView' does not contain a property with the name 'policy_typ'.

Thank you for your assistance.
ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lnshop

ASKER

It worked, thanks so much for your help.