I am trying to populate my listbox and can only populate it with System.Data.Datarow 5 times, witch is the amount of entry’s i have in my database.
I need my list box to be linked with my Database so that i can use it to select items to make changes to, so don’t want to just populate it but rather bind it.
I can’t seem to find ValueMember and DisplayMember properties. I think this may be because i’m Programming in webForms.
My Code:
using (var conn = new SqlConnection(Properties.Settings.Default.DBConnectionString))
{
conn.Open();
SqlDataAdapter daTags = new SqlDataAdapter("Select * From Tag", conn);
DataSet dsTags = new DataSet("TagCloud");
daTags.FillSchema(dsTags, SchemaType.Source, "Tag");
daTags.Fill(dsTags, "Tag");
daTags.MissingSchemaAction = MissingSchemaAction.AddWithKey;
daTags.Fill(dsTags, "Tag");
DataTable tblTag;
tblTag = dsTags.Tables["Tag"];
dplTags.DataSource = dsTags;
dplTags.DataMember = "Tag";
dplTags.DataBind();
}
You should also specify the DataValueField(ValueMember) and DataTextField(DisplayMember) properties.