我想在数据库中通过实体框架工作在组合框中显示一个值,但是组合框没有显示value.cmbCategory是组合框
var cat = db.ItemSetups.Find(txtItemID.Text);
txtItemName.Text = cat.ItemName;
txtPrice.Text = cat.Price.ToString();
txtQuantity.Text = cat.Quantity.ToString();
cmbCategory.SelectedValue = cat.ItemCategory;
答案 0 :(得分:0)
您必须指定组合框的数据源才能知道要显示的项目:
var categories = db.ItemCategory.ToList();//filter this as required
cmbCategory.DataSource = categories;
cmdCategory.DisplayItem = "CategoryName"; //or any display column you have
cmdCategory.ValueItem = "Id";
cmdCategory.SelectedItem = cat.ItemCategory;
我就是这样做的。