1

I made a very simple webpart with a grid view and and a LINQ to SQL data context object to surface some employee information for a phone list. I was able to databind the grid view directly to LINQ query objects, which worked well. However, this approach leaves you without sorting capability.

Moving forward, I wanted to use an ASP.NET LinqDataSource instead of an object datasource. I found this answer when I couldn't figure out how to actually get a LinqDatasource object to correctly render in the markup.

What the answer (and this one) fails to mention is that the LinqDataSource can't talk to any of your DataContext objects out of the box.

I found this fellow who is having a similar issue. The dude answering assumes he's talking about the SharePoint DataContext object and then a MSMVP marks his answer as correct because... banana, I guess.

Either way, here's what I have.

Markup

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Register TagPrefix="aspweb" Namespace="System.Web.UI.WebControls" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1UserControl.ascx.cs" Inherits="LinqTest2.VisualWebPart1.VisualWebPart1UserControl" %>

<asp:GridView ID="derp" runat="server" AllowSorting="True" DataSourceID="herp" 
EnableModelValidation="True">
</asp:GridView>

<aspweb:LinqDataSource ID="herp" runat="server" ContextTypeName="TydbDataContext" />

Exception

[HttpException (0x80004005): Could not load type 'TydbDataContext'.] [InvalidOperationException: Could not find the type specified in the ContextTypeName property of LinqDataSource 'herp'.]

I've verified that my LINQ to SQL DataContext type is correct in the markup and that the DataContext can be instantiated in the codebehind.

I don't care if the answer is 'not possible, go find another solution'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.