asp.net ObjectDataSource的更新从code背后 [英] asp.net ObjectDataSource Update from code behind

查看:120
本文介绍了asp.net ObjectDataSource的更新从code背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET应用程序,并在一个页面上有一个使用一个ObjectDataSource来调用位于名为设备另一个类的方法的gridview的。嗯,这类返回speciala数据表。这是工作。

I have an ASP.NET application and on one page there is a gridview that uses an ObjectDataSource to call a method that is located in another class named "Device". Well this class returns a speciala datatable. This is working.

现在我需要更新数据的方法,为此我不能使用该类设备,所以我想使用该网格的RowUpdating的方法从code后面。我甚至写了code这个方法,它是工作和方法火灾,如果用户点击在网格中的更新按钮上。

Now I need a method for updating data and for this I cannot use the class Device, so I would like to use the "RowUpdating" method of that grid from the code behind. I even wrote the code for this method and it is working and the method fires, if the user clicks the "Update"-button in the grid.

现在的问题。因为我使用ObjectDataSource,我在电网有一个更新命令,我还需要指定,为此ObjectDataSource控件更新法,这是一点。
我想从ObjectDataSource控件从我的code使用程序的RowUpdating法的背后,而不是更新方法。我目前的解决方案是在类设备,它只是追溯到通过返回命令,所以从我的code程序的RowUpdating背后做工作的方法......但是这不能成为唯一的出路如何作品。

Now to the problem. Because I am using the ObjectDataSource and I have an Update-command in that grid, I also need to specify and Update-method for this ObjectDataSource and this is the point. I want to use the RowUpdating-method from my code behind and not the update method from that ObjectDataSource. My current solution is a method in the class "Device" that just goes back via a "return" command and so the RowUpdating from my code behind is doing the job... but this cannot be the "only way how it works".

帮助和更深入的提示将不胜感激。
谢谢!

Help and further tips would be grateful. Thank You!

推荐答案

如果您使用的ObjectDataSource比你写的更新和选择方法在一类。也许你有直接写一个类为GridView控件委派更新和选择方法到其他对象。

If you use ObjectDataSource than you have to write the update and select method in one class. Maybe you have to write a class directly for that GridView to delegate the update and select methods to other objects.

我认为这将是对您有用:

I think it would be useful for you:

[DataObject(true)]
public class SomeService
{
    private Device d;
    private YourUpdaterClass yuc;

    public SomeService()
    {
        this.d = new Device();
        this.yuc = new YourUpdaterClass();
    }

    [DataObjectMethod(DataObjectMethodType.Select, true)]
    public List<YourType> Select()
    {
        return d.YourSelectMethod();
    }

    [DataObjectMethod(DataObjectMethodType.Update, true)]
    public void Update(YourType yt)
    {
        yuc.YourUpdateMethod(yt);
    }
}

和ObjectDataSource控件:

And the ObjectDataSource:

<asp:ObjectDataSource 
   ID="ObjectDataSource1"
   runat="server" 
   SelectMethod="Select"
   TypeName="SomeService"
   DataObjectTypeName="YourType"
   UpdateMethod="Update">
</asp:ObjectDataSource>

这篇关于asp.net ObjectDataSource的更新从code背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆