Reputation: 32281
I have an asp.net page with a gridview and objectdatasource. The Select Method that the objectdatasource should call is in the code behind on the same page. When I try to reference a method in the code behind I keep getting the following error:
"The type specified in the TypeName property of ObjectDataSource 'odsReplacementRequests' could not be found."
I have tried using different combinations of the typename. examples
Typename = "" Typename = Testing
Page is called Testing.aspx
<asp:ObjectDataSource ID="odsReplacementRequests" runat="server" EnablePaging="true"
SelectMethod="GetReplacementRequests" TypeName="ASP.retail_gpreplacements_aspx">
</asp:ObjectDataSource>
/// <summary>
/// Get replacements
/// </summary>
public List<ReplacementRequests> GetReplacementRequests()
{
List<ReplacementRequests> r = new List<ReplacementRequests>();
ReplacementRequests rp1 = new ReplacementRequests() { CustomerNumber = "12300", PhoneNumber = "778-123-2132" };
ReplacementRequests rp2 = new ReplacementRequests() { CustomerNumber = "12301", PhoneNumber = "778-123-2132" };
r.Add(rp1);
r.Add(rp2);
return r;
}
** Update
I've used the following code to get the typename of the code-behind class
/// <summary>
/// Page Load
/// </summary>
protected void Page_Load(object sender, EventArgs e)
{
odsReplacementRequests.TypeName = this.GetType().ToString();
}
Still no luck...
Upvotes: 0
Views: 4958
Reputation: 2321
Add the typename from where your SelectMethod exists and fix name of SelectMethod
<asp:ObjectDataSource ID="odsReplacementRequests" runat="server" EnablePaging="true"
TypeName="NameSpace.Testing"
SelectMethod="GetReplacementRequests">
</asp:ObjectDataSource>
For additional info check out MSDN on SelectMethod
Upvotes: 1
Reputation: 34846
Since you are omitting the TypeName
property on the ObjectDataSource
, it defaults to an empty string. You need to have the type name be the fully qualified name of the class where your SelectMethod
is defined (i.e. the namespace in your Testing.aspx
file plus the class name), like this:
<asp:ObjectDataSource ID="odsReplacementRequests" runat="server"
EnablePaging="true"
TypeName="YourNamespace.SubNamespace.Testing"
SelectMethod="GetReplacementRequests">
Note: You may or may not have a sub namespace, but just copy the
namespace
from your code-behind and add a dot and the class name to that end of that string.
Also, GetGPReplacementRequests
!= GetReplacementRequests
.
Your SelectMethod
attribute in the ObjectDataSource
is pointing at GetGPReplacementRequests
, but your code-behind has a method named GetReplacementRequests
, change the SelectMethod
to that name, like this:
<asp:ObjectDataSource ID="odsReplacementRequests" runat="server"
EnablePaging="true"
SelectMethod="GetReplacementRequests">
Upvotes: 4