I am using the code below to populate a webcombo with a collection of custom objects. I set the DataValueField to "Self" where Self returns the BLValidValue instance itself. When I try anduse the DataValue by (this.PriorityWebCombo.DataValue as BLValidValue).ValidValue I get an error "The DataValueField of Self was not found in the Columns collection"
Should I be able to set the DataValueField to an attribute of a custom object which returns an object ?
BLCollection<BLValidValue> ValidValues = new BLCollection<BLValidValue>();foreach (BLOrder.PriorityValidValues PriorityValue in Enum.GetValues(typeof(BLOrder.PriorityValidValues))){ BLValidValue ValidValue = new BLValidValue(); ValidValue.ValidValue = PriorityValue.ToString(); ValidValues.Add(ValidValue);}this.PriorityWebCombo.DataSource = ValidValues;this.PriorityWebCombo.DataBind();this.PriorityWebCombo.DataTextField = "ValidValue";this.PriorityWebCombo.DataValueField = "Self";
Hello jvinnell,
The DataValueField of a WebCombo is the column name from the dropdown that will be used as the source of the DataValue of the combo.
In the code you have provided, the DataSource is set to ValidValues. In the ValidValues collection, there should be a column / field name named "Self".
Please let me know if you have any questions.