/// <summary> /// Event fired when data is bound to the details view /// In this event, the checkbox values are loaded from db and updated in the view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void dvwWine_DataBound(object sender, EventArgs e) { CheckBoxList cblAttributes = (CheckBoxList)dvwWine.FindControl("cblAttributes"); if (cblAttributes != null && dvwWine.DataItem != null) { //get current Id int currentId = ((DataLayer.Wine)dvwWine.DataItem).Id; //Create the WineToWineAttribute repository BusinessLogicLayer.Repository<DataLayer.WineToWineAttribute> attributeAssignmentRepository = new BusinessLogicLayer.Repository<DataLayer.WineToWineAttribute>(); //retrieve all attribute assignments IEnumerable<DataLayer.WineToWineAttribute> attributeAssignments = attributeAssignmentRepository.GetItems().Where(cc => cc.FK_Wine == currentId); //set the checkboxes cblAttributes.Items.SetSelectedItems(attributeAssignments.Select(cc => cc.FK_WineAttribute).ToList()); } }