views:

78

answers:

1

This is my code: string SQL = "SELECT email FROM members WHERE subscribe=true"; string myConnString = Application["ConnectionString"].ToString();

        OleDbConnection myConnection = new OleDbConnection(myConnString);
        OleDbCommand myCommand = new OleDbCommand(SQL, myConnection);
        myConnection.Open();
        OleDbDataAdapter MyAdapter = new OleDbDataAdapter(myCommand);
        DataSet ds = new DataSet();
        MyAdapter.Fill(ds);

        MailsListBox.DataSource = ds;
        MailsListBox.DataBind();

        GridView1.DataSource = ds;
        GridView1.DataBind();

        myConnection.Close();

And so it looks: alt text

As you see, the GridView shows the dataset just fine, and the ListBox fails it. What happened? How can I fix it?

Thank you very much.

+2  A: 

If you don't tell your control what specific properties you want to use for display, it just calls ToString() on the items it binds to, and uses that for display. Which for most objects, ToString() by default just returns the type name.

Try setting MailsListBox.DataTextField and MailsListBox.DataValueField to "email".

womp
Thank you very much! :D
iTayb