Here is Part 3
In this article we will be seeing how to use LINQ in SharePoint 2010 to retrieve the list items and display the same in the SharePoint grid view. In SharePoint 2010 you have the ability to use LINQ syntax to query the list instead of using CAML query. In order to work with LINQ we need a command line tool called SPMetal.exe. This tool is used to generate the entity classes that is required to perform object oriented queries towards SharePoint server. It is also required to get the intellisense when we are working in Visual Studio 2010.This tool resides in 14\bin folder. In this article we are going to create a visual web part where we will be querying the items from the SharePoint list and display the result in the SharePoint grid view. Creating the entity classes:
Create Visual webpart:
namespace LinqToSQLWebpart.VisualWebPart1 { public partial class VisualWebPart1UserControl : UserControl { protected void Page_Load(object sender, EventArgs e) { MyEntityClassDataContext myEntitiesDataContext = new MyEntityClassDataContext("http://servername:2010/sites/test/");
//Querying the list var listItem = from items in myEntitiesDataContext.A select items;
//Binding the result to the grid view spGridView.DataSource = listItem; spGridView.DataBind(); } } }
Testing:
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: