当update方法接受业务类作为参数时,如何更改ObjectDataSource Updating-Event中类的属性?

时间:2010-08-09 10:20:30

标签: c# asp.net data-binding objectdatasource detailsview

我有以下情况:

我的商务舱:

public class Foo
{
 public String A {get;set;}
 public DateTime B {get;set;}
 // .. and other properties like
 public String Intern {get;set;}
}

我将该项绑定到Editmode中的DetailsView。 (我绑定一个包含Foo单个对象的List,因为我记得我只能将IEnumerable<>类绑定到DetailView) 绑定是通过ObjectDataSource

完成的
<asp:ObjectDataSource ID="odsEditfoo" runat="server" 
    SelectMethod="GetFooAsList" 
    TypeName="mynamespace.FooMethods" 
        DataObjectTypeName="mynamespace.Foo" 
        oninserting="odsEditfoo_Inserting" onupdating="odsEditfoo_Updating" 
        UpdateMethod="UpdateFoo">
    <SelectParameters>
        <asp:Parameter Name="A" Type="Int32" DefaultValue="-1" />
        <asp:Parameter DefaultValue="-1" Name="type" Type="Object" />
    </SelectParameters>
</asp:ObjectDataSource>

updatemethod看起来像

public void UpdateFoo(Foo item) 
{
   // save changes ...
}

在DetailsView中进行的更改存在于项目实例中。不幸的是,我无法展示物业实习生等所有物业。由于项目绑定到DetailView,我有所有必要的信息。在回发发生的那一刻,所有未显示的属性都会在项目中丢失。

我正在寻找一种我以前从LinqDataSource获得的方法,我在其中有一个Updating-Event,它允许我访问绑定对象,在本例中是一个foo实例,用于改变属性。我似乎无法在ObjectDataSource的Updating-Event中弄清楚如何做到这一点。我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

protected void odsEditfoo_Updating(object sender, ObjectDataSourceMethodEventArgs e)
{
  Foo item = (Foo)(e.InputParameters["item"]);
}