Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Combobox displays wrong info: "System.data.common.dbdatarecord

Posted on 2004-08-10
3
Medium Priority
?
316 Views
Last Modified: 2008-02-01
My Combo box is not displaying the contents of my table "tblcntry" it keeps displaying
Combobox displays wrong info: "System.data.common.dbdatarecord

can anyone help me correct this?

Thank you

Ted


============ CODE ================

Public Class TestDropdown
    Inherits System.Web.UI.Page

    Public MyConnect As SqlClient.SqlConnection = New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("SQLDB_Test"))
    Public MyCommandCMBCountry As SqlClient.SqlCommand = New SqlClient.SqlCommand("SELECT Cntry FROM tblCntry ORDER BY Cntry", MyConnect)
    Public MyReaderCMBCountry As SqlClient.SqlDataReader
    Protected WithEvents cmbCountry As System.Web.UI.WebControls.DropDownList

    Public MyCommand As SqlClient.SqlCommand

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    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
        MyConnect.Open()
        MyReaderCMBCountry = MyCommandCMBCountry.ExecuteReader(CommandBehavior.CloseConnection)
        cmbCountry.DataSource = MyReaderCMBCountry
        cmbCountry.DataBind()
        MyReaderCMBCountry.Close()
        MyConnect.Close()
    End Sub

End Class
0
Comment
Question by:tcalbaz
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
daffodils earned 1000 total points
ID: 11766497
You need to set the

"DataTextField" to the column name you want to display on the combo box.
"DataValueField" to the column name you want to retrieve as value.

Lets say you have a Customer table,
Setting "DataTextField" to the column "Customer ID" will display all customer IDs in the combo box.
Setting "DataValueField" to the column "Customer Name" will retrieve the Customer Name as the SelectedValue corresponding to the Customer ID selected in the combobox.

DataTextField - Gets or sets the field of the data source that provides the text content of the list items.
DataValueField - Gets or sets the field of the data source that provides the value of each list item.
0
 
LVL 8

Expert Comment

by:daffodils
ID: 11766556
A mistake in the exxample above..

Setting "DataTextField" to the column "Customer ID" will display all customer IDs in the combo box.

Setting "DataValueField" to the column "Customer Name" will retrieve the Customer Name as the <u>"SelectedItem.Value"</u> property of the the CustomerID selected in the combobox.
 
 
 

0
 
LVL 1

Author Comment

by:tcalbaz
ID: 11766862
BINGO!

Thank you daffodils !

Ted
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question