You need to assign the .DataValueField of the contorl to the column in the
DataSet you want for the value , and the the DataTextField to the column
you want to display in the drop-down.

               DropDownList1.DataValueField="pub_id";
               DropDownList1.DataTextField="pub_name";
               DropDownList1.DataBind();


Steve Holak
Senior Software Architect

Brokerage Concepts IS Dept.
610-491-4879

email:  [EMAIL PROTECTED]



                    Kirk Jackson
                    <Kirk.Jackson@INTER        To:     [EMAIL PROTECTED]
                    GEN.CO.NZ>                 cc:
                    Sent by: dotnet            Subject:     Re: [DOTNET] DropDownList 
binding
                    discussion
                    <[EMAIL PROTECTED]
                    ELOP.COM>


                    05/02/2002 09:06 PM
                    Please respond to
                    dotnet discussion






If you don't specify a DataTextField in the drop down list's properties,
then I think it just defaults to calling ToString() on each Data Item.

You probably also need a DataValueField.

Kirk



-----Original Message-----
From: Dawid Greyvenstein [AST EH] [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 2 May 2002 9:18 p.m.
To: [EMAIL PROTECTED]
Subject: [DOTNET] DropDownList binding


I am trying to bind a DropDownList  to a sqlDataReader. I get the
correct amount of options in the list, but the text is
'System.Data.Common.DbDataRecord' for all the options in the list. What
am I doing wrong?

      private void Page_Load(object sender, System.EventArgs e)
      {

            // connect to database
            SqlConnection SqlConn = new SqlConnection(connStr);
            SqlConn.Open();
            // get data
            string SQL = "SELECT pub_id,pub_name FROM publishers ORDER
BY pub_name";
            SqlCommand sqlCommand1 = new SqlCommand(SQL,SqlConn);
            SqlDataReader reader = sqlCommand1.ExecuteReader();
            // do binding
            DropDownList1.DataSource = reader;
            DropDownList1.DataBind();
      }

______________________________________________

"This information is intended only for the person or entity to which it
is addressed and may contain private, confidential, proprietary and/or
privileged material and may be subject to confidentiality agreements.

Any review, retransmission, dissemination, or any other use of or taking
of any action in reliance upon this information, by persons or entities
other than the intended recipient, is prohibited.

If you received this in error, please contact the sender and delete the
material from all storage media.

The company is neither liable for proper, complete transmission of the
information contained in this communication, any delay in its receipt or
that the mail is virus-free"

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to