bugzy
bugzy

Reputation: 7096

Reference ObjectDataSource DataObjectType from ObjectDataSource.OnUpdating Event

I have an ObjectDataSource which uses a DataObjectType (Name). In this case EmpRow to pass update and insert parameters instead of passing individual parameters.

The ODS is used by the FormView which has two Multi Select ListBox controls. Because the ListBox controls will only pass one selected item, I need to properly add all selected values to the DataObject before the datasource updates.

So in the ObjectDataSource.OnUpdating event I want to iterate the selected items and adjust the proper values in the DataObject that is passed to the dataource update method.

My problem is that I can't figure out how to get a reference to the dataobject. It looks like to only way to it would be through the OrderedDictionary? Is that Right? Some how I need to reference the EmpRow object and update a couple of property values?

Any Ideas?

protected void dsDetail_Updating(object sender,      
    System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs e)
{

    OrderedDictionary od = (OrderedDictionary) e.InputParameters;
    IDictionaryEnumerator castRowEnum = (IDictionaryEnumerator)od.GetEnumerator();

    //Now I somehow want to create an EmpRow object from the 
    //passed DataObjectType of the datasource

    FormView fv = (FormView)FormView1;
    ListBox lstLanguages = (ListBox)fv.Row.FindControl("lstSpokenLanguages");
    ListBox lstSECPSTypes = (ListBox)fv.Row.FindControl("lstSECPSTypes");

    string strSpokenLanguages = "";
    string strSECPSTypes = "";

    foreach (ListItem item in lstLanguages.Items)
    {
        if (item.Selected)
        {
            strSpokenLanguages += item.Value + ",";
        }
    }
    strSpokenLanguages = strSpokenLanguages.Substring(0,                               
                                       (strSpokenLanguages.Length - 1));


    foreach (ListItem item in lstSECPSTypes.Items)
    {
        if (item.Selected)
        {
            strSECPSTypes += item.Value + ",";
        }
    }
    strSECPSTypes = strSECPSTypes.Substring(0, (strSECPSTypes.Length - 1));

    //now i need to assign these values to the proper data object properties
    //EmpRow.cSECPSTypes = strSECPSTypes;
    //EmpRow.cSpokenLanguages = strSpokenLanguages;
}

Upvotes: 1

Views: 712

Answers (1)

bugzy
bugzy

Reputation: 7096

I have reached a solution which is to do:

EmpRow empRow = (EmpRow) e.InputParameters[0];

Upvotes: 1

Related Questions