+3  A: 

Hi when databinding (to anything) you need to set the DataTextField and DataValueField of your DropDownList. In your case you should use the following code

List<ListItem> users = new List<ListItem>();
foreach (SubscriptionUser su in subscriptionDetails.UserList)
{
    users.Add(new ListItem(su.FirstName + " " + su.LastName, su.EmailAddress));
}
ddlPrimaryContact.DataTextField = "Text";
ddlPrimaryContact.DataValueField = "Value";
ddlPrimaryContact.DataSource = users;
ddlPrimaryContact.DataBind();
mdresser
Thanks. I did figure this out in the meanwhile. I guess I was assuming this "matching" would be done automatically, but apparently I was wrong...
Farinha
+2  A: 

You should bind your dropdown list as :

ddlPrimaryContact.DataSource = users;
ddlPrimaryContact.DataTextField = "Value";
ddlPrimaryContact.DataValueField = "Text";
ddlPrimaryContact.DataBind();

If you ask why, as far as I know, databound controls takes texts and values (if they are not supplied like above) by calling the ToString method for each item in datasource collection. So each ListItem in your collection return it's Text property by ToString method.

Canavar
+1  A: 

Or, alternatively, you could bind it this way. (Assuming you can add a readOnly property to SubscriptionUser called FullName (which returns su.FirstName + " " + su.LastName)

ddlPrimaryContact.DataSource = subscriptionDetails.UserList;
ddlPrimaryContact.DataBind();

then, in your ASPX page put:

<asp:DropDownList id="ddlPrimaryContact" runat="server" DataTextField="FullName" DataValueField="EmailAddress" />
davewasthere
+1  A: 

you can aslo directly add listitem to dropdown..

List<ListItem> users = new List<ListItem>();
        for (int count = 0; count < 10; count++)
        {
            ListItem li = new ListItem("List " + count.ToString(), count.ToString());
            ddl.Items.Add(li);
        }
Muhammad Akhtar