# code for databinding with combobox
try {
SqlConnection conn = new SqlConnection();
conn.ConnectionString = Properties.Settings.Default["MyConnStr"].ToString();
conn.Open();
string select_cats="select * from BusinessCategory";
SqlDataAdapter sda=new SqlDataAdapter(select_cats,conn);
DataTable dt=new DataTable();
sda.Fill(dt);
//databinding to the combobox
TestcomboBox.DataSource = dt.DefaultView;
TestcomboBox.DisplayMember = "Description";
TestcomboBox.ValueMember = "BusCatID";
}
catch (Exception exc) {
//MessageBox.Show(exc.Message);
}
Here we see 'Description' is used here as text property and 'BusCatID' is used here as value property with combo box.
No comments:
Post a Comment