locked
FormView_Iteminserting issue RRS feed

  • Question

  • User-239001081 posted

    Hi,

    I have a Formview with an ItemInserting method attached to it.

    I set a new value to a float type field with the following code

    DropDownList DDL = FormView1.FindControl("DropDownList1") as DropDownList;
    e.Values["floatField"] = DDL.SelectedValue;

    which give me error 

    Failed to set one or more properties on type property.  2.5 is not a valid value for Int16

    If i use the following command to set the new value everything works fine.

    e.Values["rooms"] = 2.5;

    Any idea what is the problem here ?

    -

    ddd

    Sunday, July 24, 2016 11:59 AM

Answers

  • User283571144 posted

    Hi shtrudel,

    Any idea what is the problem here ?

    As far as I know, 'DDL.SelectedValue''s type is string.

    More details, you could refer to follow link:

    https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedvalue(v=vs.110).aspx

    [BindableAttribute(true, BindingDirection.TwoWay)]
    [BrowsableAttribute(false)]
    [ThemeableAttribute(false)]
    public virtual string SelectedValue { get; set; }

    So you could not set this value to a parameter which type is 'int'.

    I suggest you could use follow code:

    e.Values["floatField"]  =  Convert.ToInt16(DDL.SelectedValue);

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 24, 2016 12:11 PM