ListViewByQuery Webpart in SharePoint 2010

This is a quick post on writing a custom ListViewByQuery WebPart on a designated SharePoint 2010 site. By using a ListViewByQuery Control, developers can easily create a default looking ListView Webpart with added bespoke functionality as they have the luxury of rendering desired caml query to pull data out from an existing list. Perhaps the biggest advantage is that you can present ListViewByQuery WebPart on a different site especially when you want to work within the confines of your SharePoint permission security layer.

I have deployed the ListViewByQuery WebPart inside a custom webpart. I would recommend you to use Visual Studio 2010Empty SharePoint Project (then) – Add New Item – Web Part (Template) for this solution. This will give you all the mapped folders and files etc so nothing for you to worry about. Open your UserControl.ascx File and add the following.


<SharePoint:ListViewByQuery runat="server" id="LVWP" />

Now open the UserControl.ascx.vb file and add the following.


LVWP.List = SPContext.Current.Web.Lists("Some List")
Dim caml As SPQuery = New SPQuery(LVWP.List.DefaultView)
caml.Query = "<caml>Desired CAML Syntax</caml>"
LVWP.Query = caml

This is it, now your ListViewByQuery WebPart is ready to be used on the page. For full access to its properties and methods follow the link.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.listviewbyquery.aspx

Noteworthy Anomalies

I have found ListViewByQuery WebPart known for not having:

a)    SharePoint 2010 Ribbon being activated when you click on the List Item.

b)    No Access to DataSheet View.

c)    No ‘Add New Item’ option either.

Needless to say, it is a good reporting tool. Please continue on Google Trails or MSDN SharePoint 2010 Development & Programming Forum if you want to further investigate the above.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s