【问题标题】:How to change properties of a class in the ObjectDataSource Updating-Event when the update method accepts the business class as parameter?当更新方法接受业务类作为参数时,如何更改 ObjectDataSource 更新事件中类的属性?
【发布时间】:2010-08-09 10:20:29
【问题描述】:

我有以下情况:

我的商务舱:

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 对象的列表,因为我记得我只能将 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>

更新方法看起来像

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

在 DetailsView 中完成的更改存在于项目实例中。不幸的是,我无法显示每个属性,例如属性 Intern。由于该项目绑定到 DetailView 我有所有必要的信息。回发发生时,项目中所有未显示的属性都将丢失。

我正在从 LinqDataSource 中寻找一种我习惯使用的方法,在那里我有一个 Updating-Event 允许我访问绑定对象(在本例中为 foo 的实例)来更改属性。我似乎无法在 ObjectDataSource 的更新事件中弄清楚如何做到这一点。我必须怎么做才能解决这个问题?

【问题讨论】:

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


    【解决方案1】:

    我找到了解决办法:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-16
      • 2011-11-20
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-21
      • 1970-01-01
      相关资源
      最近更新 更多