Here’s the code I have. It works. The only problem is that the first index of the drop down box gets wiped out (“Select Source Database”) when I bind the data set to its data source.
I want to bind the data set and INCLUDE the first index “Select Source Database”.
How can I modify my code to accomplish this?
protected void ddlServer_SelectedIndexChanged(object sender, EventArgs e)
{
ddlSourceDatabases.Items.Clear();
ddlSourceDatabases.Items.Add("Select Source Database");
lbxSourceTables.Items.Clear();
if (ddlSourceServers.SelectedIndex != 0)
{
try
{
ddlSourceDatabases.DataSource = Database.GetDatabases(ddlSourceServers.Text);
ddlSourceDatabases.DataTextField = "name";
ddlSourceDatabases.DataValueField = "name";
ddlSourceDatabases.DataBind();
}
catch (Exception)
{
}
}
}
Insert your item after data binding to the first position: