I know for a fact that the function below (Database.GetTables) is bringing back the value/s that I want. However, when I try to do the binding to the list box, nothing populates in it. Am I missing anything? What’s the correct way to populate a list box from a datasource?
protected void ddlDatabase_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlDatabases.SelectedIndex != 0)
{
lbxTables.DataSource = Database.GetTables(ddlServers.Text, ddlDatabases.Text);
ddlDatabases.DataValueField = "name";
ddlDatabases.DataBind();
}
}
I have also tried:
ddlDatabases.DataTextField = "name";
And no luck.
You’re starting by setting up the DataSource on your listbox control, but end up calling DataBind on the dropdown menu.
Try this:
You can also add in the
DataValueFieldandDataTextFieldonlbxTablesthere beforelbxTables.DataBind();