Thursday, March 29, 2012

Using an ObjectDataSource in Sharepoint

A Co-worker was trying to use an ObjectDataSource within a UserControl within SharePoint.

After a bit of research. We learned one must use the fully qualified name of the class and assembly when defining the TypeName.

So we did it, but in the code behind.

ASCX Snippet

   1: <asp:ObjectDataSource ID="odsProfit" runat="server" 
   2:     SelectMethod="GetData">
   3:         <SelectParameters>
   4:             <asp:Parameter Name="DataID" Type="Int32" />
   5:         </SelectParameters>
   6: </asp:ObjectDataSource>

ASCX.cs Snippet

   1: protected void Page_Init(object sender, EventArgs e)
   2: {
   3:     odsProfit.TypeName = new ProfitManager()
   4:                                 .GetType()
   5:                                 .AssemblyQualifiedName;
   6: }

I just thought I would share.



  1. Hi Justin,
    don't have to do in codebehind, instead we can use like this :

    TypeName="MyAssembly, $SharePoint.Project.AssemblyFullName$"

    1. edanan-

      Good to know, thanks for sharing.