当更新方法接受业务类作为参数时,如何更改 ObjectDataSource 更新事件中类的属性?
我有以下情况:
我的商务舱:
public class Foo
{
public String A {get;set;}
public DateTime B {get;set;}
// .. and other properties like
public String Intern {get;set;}
}
我将该项目绑定到编辑模式下的详细信息视图。 (我绑定了一个包含单个 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 中完成的更改存在于项目实例中。不幸的是,我无法显示每个属性,例如属性 Intern。由于该项目绑定到 DetailView,我拥有所有必要的信息。回发发生时,项目中所有未显示的属性都会丢失。
我正在寻找一种我习惯从 LinqDataSource 获得的方法,其中我有一个更新事件,它允许我访问绑定对象(在本例中是 foo 的实例)以更改属性。我似乎无法弄清楚如何在 ObjectDataSource 的更新事件中执行此操作。我必须做什么来解决这个问题?
I have the following situation:
My business class:
public class Foo
{
public String A {get;set;}
public DateTime B {get;set;}
// .. and other properties like
public String Intern {get;set;}
}
I'm binding that Item to a DetailsView in Editmode. (I bind a List containing a single object of Foo, becuase I do recall that I can only bind IEnumerable<> classes to the DetailView)
The binding is done via a 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>
The updatemethod looks like
public void UpdateFoo(Foo item)
{
// save changes ...
}
The changes that are done in the DetailsView are present in the item instance. Unfortunetly I can't display every property such as the property Intern. As the item is bound to the DetailView I have all the necessary information. All none displayed properties are lost in the item the moment the postback occurs.
I'm looking for a way I'm used to have from the LinqDataSource, where I have an Updating-Event that allows me access to the bound object, in this case an instance of foo, to alter properties. I can't seem to figure out how to this in the Updating-Event of the ObjectDataSource. What must I do to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案:
I found the solution: