Check this sample
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
BindDropDown(cmbContinents, "select * from Continents", "ContinentName", "Id");
}
private void BindDropDown(ComboBox comboBox, string query, string text, string value)
{
string strConnString = ConfigurationSettings.AppSettings["constr"];
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
sda.Fill(ds);
comboBox.DisplayMember = text;
comboBox.ValueMember = value;
DataRow row = ds.Tables[0].NewRow();
row[text] = "Please Select";
row[value] = "0";
ds.Tables[0].Rows.InsertAt(row, 0);
comboBox.DataSource = ds.Tables[0];
}
}
}
}
private void cmbContinents_SelectedIndexChanged(object sender, EventArgs e)
{
BindDropDown(cmbCountries, "select * from Countries where ContinentId=" + cmbContinents.SelectedValue, "CountryName", "Id");
}
}