public void SetDropDownList() { using (var ctx = new ProductMNEntities()) { var cateDomain = new CategoryDomain(ctx); var supDomain = new SupplierDomain(ctx); var suppliers = supDomain.GetAll().Select(s => new DropDownListVMs { Text = s.CompanyName, Value = s.SupplierID.ToString() }).ToList(); var categories = cateDomain.GetAll().Select(c => new DropDownListVMs { Text = c.CategoryName, Value = c.CategoryID.ToString() }).ToList(); var discontinueds = new List <DropDownListVMs> { new DropDownListVMs { Text = "True", Value = "true" }, new DropDownListVMs { Text = "False", Value = "false" }, }; Suppliers_ID.DataTextField = "Text"; Suppliers_ID.DataValueField = "Value"; Suppliers_ID.DataSource = suppliers; Suppliers_ID.DataBind(); Categories_ID.DataTextField = "Text"; Categories_ID.DataValueField = "Value"; Categories_ID.DataSource = categories; Categories_ID.DataBind(); Discountinued.DataTextField = "Text"; Discountinued.DataValueField = "Text"; Discountinued.DataSource = discontinueds; Discountinued.DataBind(); } }
public void DropDownListSelected() { using (var ctx = new ProductMNEntities()) { var domain = new ProductDomain(ctx); var product = domain.FindById(_productId); Categories_ID.ClearSelection(); Categories_ID.Items.FindByValue(product.CategoryID.ToString()).Selected = true; Suppliers_ID.ClearSelection(); Suppliers_ID.Items.FindByValue(product.SupplierID.ToString()).Selected = true; Discountinued.ClearSelection(); Discountinued.Items.FindByValue(product.Discontinued.ToString()).Selected = true; } }