Question

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.

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.

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!

Was it helpful?

Solution

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);
    }
}

And the ObjectDataSource:

<asp:ObjectDataSource 
   ID="ObjectDataSource1"
   runat="server" 
   SelectMethod="Select"
   TypeName="SomeService"
   DataObjectTypeName="YourType"
   UpdateMethod="Update">
</asp:ObjectDataSource>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top