Question

I'm trying to call a function using the SelectMethod of an ObjectDataSource.

<asp:ObjectDataSource runat="server" 
                      ID="odsDocuments" 
                      TypeName="ClassA" 
                      SelectMethod="Documents.GetDocuments" />

Where "Documents" is an instance of another class as a public property within "ClassA" and "GetDocuments" is a function within the "Documents" class.

I keep getting an error saying that the function can't be found (obviously the function exists and there's no issue with levels of access).

Any idea where I'm going wrong or is this syntax not really possible using this method?

Was it helpful?

Solution

I don't think the ObjectDataSource supports the dot notation; I think the ODS has to have the method directly on the object specified in the type. However, I know you can, behind the scenes, change the underlying object the data source is using to call the method on. So what I mean is in one of the events (I believe ObjectCreated event), you could change the context to point to the Document object, so that everything is evaluated correctly.

OTHER TIPS

You can implement a wrapper method in ClassA, like this:

public object GetDocuments()
{
    return Documents.GetDocuments();
}

And use the data source this way:

<asp:ObjectDataSource runat="server" 
                      ID="odsDocuments" 
                      TypeName="ClassA" 
                      SelectMethod="GetDocuments" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top