[Mono-list] DropDownList doesnt work correctly

Jones, Larry LJones@Lithonia.com
Fri, 2 May 2003 01:20:02 -0700


Here is another problem I ran into.  I am populating a dropdownlist with
fields from a SQL file.  I give it the DataTextField, but it displays not
the name in the ddl but the data type, like:
System.Data.Common.DbDataRecord.  Here is the listing:
----------------------------------------------------------------------------
-----
<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
public void Page_Load(Object Sender, EventArgs e)
{
	SqlDataReader reader;
       string connectionString = 
          "Server=SERVER;" +
          "Database=pubs;" +
          "User ID=sa;" +
          "Password=gon23zo;";
       SqlConnection dbcon;
       dbcon = new SqlConnection(connectionString);
       dbcon.Open();
       SqlCommand dbcmd = dbcon.CreateCommand();
       string sql = 
           "SELECT au_fname, au_lname " +
           "FROM Authors";
       dbcmd.CommandText = sql;
       reader = dbcmd.ExecuteReader();

	ddlAuthors.DataSource = reader;
	ddlAuthors.DataTextField = "au_lname";
	ddlAuthors.DataBind();

       // clean up
       reader.Close();
       dbcon.Close();
 }
</script>

<Html>
<Body>
<H2>Testing Sql</H2>
<form runat="server">

<asp:DropDownList ID="ddlAuthors" runat="Server" />

</form>
</Body>
</Html>
----------------------------------------------------------------------------
--------

Larry Jones
Hydrel/Lithonia Lighting