Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
830
Setting DataValueField to a custom object
posted

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 and
use 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";

 

 

 

 

 

 

Parents
No Data
Reply
  • 7570
    Suggested Answer
    posted

    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.

Children
No Data