Can't access DataItem in FormView when updating

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bresco

    Can't access DataItem in FormView when updating

    I'm using ObjectDatasourc e in combination with a Formview. The
    ObjectDatasourc e is connected to a FormView.

    I have a business object property which I can't update through the normal
    binding since it's a custom enum type. I managed to access the buinsess
    object through the FormView.DataIt em property in the OnDataBinding event so
    that I can fill a dropdownlist with the correct value by casting the enum
    type to an int.

    However,when trying to get the data OUT of the control into the business
    object I can't seem to get access to the DataItem (i.e. the business object)
    since it's null in the OnItemInserting and OnItemUpdating events. I tried
    all kinds of things to get hold of the business object but nothing seems to
    work.

    Anyone know how to get the DataItem when saving?


  • Bresco

    #2
    Re: Can't access DataItem in FormView when updating


    "Bresco" <bresco@mixmast er.orgwrote in message
    news:gg5ran$tm9 $1@aioe.org...
    I'm using ObjectDatasourc e in combination with a Formview. The
    ObjectDatasourc e is connected to a FormView.
    >
    I have a business object property which I can't update through the normal
    binding since it's a custom enum type. I managed to access the buinsess
    object through the FormView.DataIt em property in the OnDataBinding event
    so that I can fill a dropdownlist with the correct value by casting the
    enum type to an int.
    >
    However,when trying to get the data OUT of the control into the business
    object I can't seem to get access to the DataItem (i.e. the business
    object) since it's null in the OnItemInserting and OnItemUpdating events.
    I tried all kinds of things to get hold of the business object but nothing
    seems to work.
    >
    Anyone know how to get the DataItem when saving?
    >
    Well, I 'solved' it, although I still find it very unintuitive that ASP.NET
    does not make the DataItem available in the OnInserting, OnUpdating events.

    Here's what I did:

    protected void FormView1_ItemU pdating(object sender, FormViewUpdateE ventArgs
    e)
    {
    DropDownList ddl = this.FormView1. FindControl("Dr opDownlist1") as
    DropDownList;
    e.NewValues.Add ("EnumTypePrope rty", ddl.SelectedInd ex.ToString());
    }

    For some reason, ASP.NET seems to automatically cast the string in the
    EnumTypePropert y to EnumType before putting it in the property.

    Note that to get the property into the DropDownList you have to handle the
    DropDownList1_D ataBinding like:

    protected void DropDownList1_D ataBinding(obje ct sender, EventArgs e)
    {
    MyBizObject bo = FormView1.DataI tem as BizObject;
    DropDownList ddl = this.FormView1. FindControl("Dr opDownlist1") as
    DropDownList;
    ddl.SelectedInd ex = (int)bo.EnumTyp ePropererty;
    }

    you can't handle the FormView1_DataB inding since the DataItem will then be
    NULL.


    Comment

    Working...