문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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" />
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top