Solved

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

Posted on 2004-08-10
3
301 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 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
BINGO!

Thank you daffodils !

Ted
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now