5
Reply

combo box with default text

Enos

Enos

Dec 4 2014 4:19 AM
780
Hi ,
 
 
i have a combo box which loads from the database. Now i want default text on the combo box ("--Please Select--") to appear on top of the list, it must show the text whithout the user even opened the combo box. Also when the user clear the combo box, the default text will be "--Please Select--"
 
 
this is how i bindeed it ;
 
private void LoadCombo()
{
try
{
oConnection = new SqlConnection(_connectionString);
oCommand = new SqlCommand("select * from tbldpt", oConnection);
oAdapter = new SqlDataAdapter(oCommand);
oConnection.Open();
oDataset = new System.Data.DataSet();
SqlDataReader oReader = oCommand.ExecuteReader();
while (oReader.Read())
{
string _Combobox = oReader["Departmentname"].ToString();
cboDepartment.Items.Add(_Combobox);
}
oReader.Close();
oConnection.Close();
}
catch(Exception ex)
{
}
}
 
 

Answers (5)