Tuesday, September 18, 2007

List View Control (Quick way to embed lists into a webpart)

Hey folks!!!
It's been a pretty long time. I've been on a lot of projects in between and have been pretty much heads down since the last post. I figure I'll start off the next few rounds with a use control that across the board called the List View Control.

The SharePoint List View control is a very useful control that is leveraged in the ListView WebPart to display List. It's location is in the common Microsoft.SharePoint.WebControls namespace and it only needs a 2 properties to really show all of it's value. Internally this control interprets List Views and field values and renders them in a SPGridView control. It's nice to be able to simply leverage this control without doing all of the work.

Here's a code sample that should explain exactly how to use it:

namespace TAS.Examples
{
class ListViewExample : System.Web.UI.WebControls.WebParts.WebPart
{

Microsoft.SharePoint.WebControls.ListView view;

protected override void CreateChildControls()
{
view = new ListView();
SPList list = SPContext.Current.Web.Lists["
view.ListID = list.ID;
view.ViewID=list.DefaultView.ID;
Controls.Add(view);
}
protected override void RenderContents(writer)
{
view.renderControl(writer);
}
}
}

This is only a light sample of what you can do with this web control. By leveraging this control you know longer have to fight with an SPGridView Control or leverage the "RenderAsHTML" method of a List just to enable your WebParts and pages to leverage SharePoints Out of the box list capabilities.

Hope this helps,

~:)

14 comments:

Anonymous said...

How do I embed the New or Edit form version of a list in my custom web part. I am sure I have seen people render the edit form inside their custom web part but can't figure it out. I had planned to create a custom web part that allows you to configure the web part to select an existing list and it would render the edit form for you so you could add items to the list from any page within the site. Any help in working out how to get the edit form for a list and render it in a web part would be greatly appreciated.

Eric Stallworth said...

I'll Tell you what, How about I post on that today :)

Eric Stallworth said...

I'll do a more indepth post on this a bit later, but I think this should get you up and running:

Using SharePoint Form Controls

Michele A said...

Thank a lot!
I'm searching for this info the last 2 day!!

Great

Anonymous said...

Super solution but filtering and sorting the data isn't possible (collapsing of Group By views doesn't work ether). I'm searching for a solution since a while but didn't find it yet...

Michele A said...

it is not true
filtering and sorting is possible with ListViewByQuery Control

Anonymous said...

Hey,

The ListViewByQuery renders also a complete list with headers and items. But when I click on one of the columns in the header, he doesn't do a postback to sort or filter...

my C# code:

SPWeb spWeb = SPControl.GetContextWeb(Context);
SPList list = spWeb.Lists[listId];
SPQuery query = new SPQuery(list.Views[viewName]);
myListQuery.List = list;
myListQuery.Query = query;

my html:

<SharePoint:ListViewByQuery ID="myListQuery" runat="server" />

Anonymous said...

Thank a lot. But, WebPart cannot render items when the view is contain Ajax (if view have GroupBy). Any body help?

gbelzile said...

Do you know if there is a way of showing a specific folder in the list?

Anonymous said...

I found this site using [url=http://google.com]google.com[/url] And i want to thank you for your work. You have done really very good site. Great work, great site! Thank you!

Sorry for offtopic

Anonymous said...

[url=http://platinconne.freehostia.com/map.html]free movies download[/url] parampampam!

Anonymous said...

topic02, [url=http://www.chop.edu/forum/user/profile/8207.page]buy klonopin no prescription[/url], ;-( abj, http://www.chop.edu/forum/user/profile/8207.page klonopin no prescription *sorry*, [url=http://www.chop.edu/forum/user/profile/8208.page]purchase xanax 2mg[/url], :-( jct, http://www.chop.edu/forum/user/profile/8208.page buy xanax 2mg *sorry*, [url=http://forum.cprs.ca/default.aspx?g=posts&m=6]order adipex online[/url], ;-( kwv, http://forum.cprs.ca/default.aspx?g=posts&m=6 order adipex :-(, [url=http://forum.cprs.ca/default.aspx?g=posts&m=7]buy alprazolam without prescription[/url], ;-( rgt, http://forum.cprs.ca/default.aspx?g=posts&m=7 buy alprazolam without prescription ;-(, [url=http://forum.cprs.ca/default.aspx?g=posts&m=8]order ambien no prescription[/url], :-) oop, http://forum.cprs.ca/default.aspx?g=posts&m=8 ambien no prescription :-(

Anonymous said...

hi! [url=http://esnips.com/web/minnaregina/]Hello. And Bye.
[/url] http://esnips.com/web/minnaregina/ free nude video clips of milfs
thanks!
free nude video clips of milfs

Anonymous said...

Greetings!
Please look our cheapest prices forAmbien. Best proposition guarantied. Self-indulgent Delivery
[url=http://www.testriffic.com/user/MygdsAnge/]mixing carisoprodol and xanax[/url]
[url=http://www.testriffic.com/user/KbmxiZucn/]xanax long term effects[/url]
[url=http://www.testriffic.com/user/VyrklEzkn/]buy xanax bars[/url]
[url=http://www.testriffic.com/user/BkrgjYqpj/]buy com.uy site xanax xanax.html zyworld.com[/url]
[url=http://www.testriffic.com/user/KszihLcyc/]xanax pill book[/url]
[url=http://www.testriffic.com/user/AhtonVztu/]xanax death + alcohol[/url]
[url=http://www.testriffic.com/user/KspnhVfvt/]buy next day Xanax[/url]
[url=http://www.testriffic.com/user/CeyhuYjkp/]advanced book guest legend show xanax[/url]
[url=http://www.testriffic.com/user/UwfwzMprd/]how to inject xanax pills[/url]
[url=http://www.testriffic.com/user/HjlksDftc/]buy cheap informix.susu.ac.ru link tramadol tramadol.html xanax[/url]
[url=http://www.testriffic.com/user/BfbixOxhp/]amount overdose xanax[/url]
[url=http://www.testriffic.com/user/MeadqOwto/]greenstone xanax 2 mg[/url]
[url=http://www.testriffic.com/user/BhjhdKnvb/]spca xanax[/url]
[url=http://www.testriffic.com/user/RgdroFimf/]comment picture post xanax[/url]
[url=http://www.testriffic.com/user/XjpemTjci/]xanax high[/url]
[url=http://www.testriffic.com/user/JzcxbVahh/]xanax bar effects[/url]
[url=http://www.testriffic.com/user/UvmijQgom/]sniffing xanax[/url]
[url=http://www.testriffic.com/user/YwaaiQskb/]how to get xanax[/url]
[url=http://www.testriffic.com/user/GembzCewv/]adrenalin email h1.ripway.com link xanax.html[/url]
[url=http://www.testriffic.com/user/ZipedXkxc/]xanax 2c guaranteed overnight delivery[/url]
[url=http://www.testriffic.com/user/AkalvVbpx/]buy Xanax no perscription[/url]
[url=http://www.testriffic.com/user/ZclsrHhsq/]xanax doseages[/url]
[url=http://www.testriffic.com/user/MnxdkHsuc/]xanax pill id[/url]
[url=http://www.testriffic.com/user/FmxccHnbx/]xanax ativan[/url]
[url=http://www.testriffic.com/user/ClbtzMfvt/]off xanax[/url]
[url=http://www.testriffic.com/user/EyfsnEdby/]book buy com guest millard online site xanax[/url]
[url=http://www.testriffic.com/user/CkcibDkzb/]how to stop taking xanax[/url]
[url=http://www.testriffic.com/user/BespfUtkg/]buy info site xanax xanax.html zyworld.com[/url]
[url=http://www.testriffic.com/user/HzdkbAjjb/]interaction between xanax and prozac[/url]
[url=http://www.testriffic.com/user/YmrloEhzg/]alprazolam book guest nl site xanax[/url]
[url=http://www.testriffic.com/user/ZhxdqHvxu/]xanax or paxil[/url]
[url=http://www.testriffic.com/user/ZzzmzSnlg/]generic xanax names[/url]
[url=http://www.testriffic.com/user/LplbaRqrg/]picture of generic xanax[/url]
[url=http://www.testriffic.com/user/OnxenGuyq/]xanax pharmacy affiliate[/url]
[url=http://www.testriffic.com/user/YcajnNhcq/]com file odessa.blogs.eurosport.com site xanax.html[/url]
[url=http://www.testriffic.com/user/ZawmbHifp/]where to buy Xanax online[/url]
[url=http://www.testriffic.com/user/AlfmiYmbd/]2006 by casino message post posted xanax[/url]
[url=http://www.testriffic.com/user/LjpqqBezy/]blog overdose xanax[/url]
[url=http://www.testriffic.com/user/TxufjSauf/]link links.com xanax.se[/url]
[url=http://www.testriffic.com/user/UztbrSuah/]alprazolam guestbook.html inurl xanax[/url]