SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using SharePoint Server 2007 Enterprise with Windows Server 2008 Enterprise, and I am using Publishing Portal Template. I am developing using VSTS 2008 + C# + .Net 3.5. I have defined a custom list manually on a SharePoint site (all column types of the custom list are SharePoint built-in types), and I want to define some customized rules to filter this list to display only a part of the list. Any reference code?


Here is my current code. I have used such code to retrieved the items I need, but how to display the retrieved items in a SharePoint list?

            SPSite oSiteCollection = SPContext.Current.Site;
            SPList oList = oSiteCollection.AllWebs[0].Lists["PeopleTest"];
            SPQuery oQuery = new SPQuery();
            oQuery.Query = "<Where><Eq><FieldRef Name='Department'/>" +
                    "<Value Type='Text'>Computer</Value></Eq></Where>";
            SPListItemCollection collListItems = oList.GetItems(oQuery);

            foreach (SPListItem oListItem in collListItems)
share|improve this question
Wouldn't a normal SharePoint View satisfy your requirements? – Thomas Vochten Dec 10 '09 at 7:41
Thanks Thomas! I have updated my reply in EDIT1 section. The built-in filters and views are not enough for my complex application specific logics. Any solutions? – George2 Dec 10 '09 at 9:15
up vote 2 down vote accepted

You could create a view (either manually or programmatically), and then get a reference to this SPView, and call RenderAsHtml() on it. This renders like an SPGridView (which is what you want).

Alternatively, you could use an SPDataSource. You can then bind this SPDataSource to an SPGridView. This can be done declaratively with ASPX/ASCX markup only.

Let me guess, you want a code snippet? :)

share|improve this answer
Cool, question answered! – George2 Dec 10 '09 at 12:05

Your filter looks pretty straightforward, but I would go with a Data View Web Part (DVWP). No back end code, and easily configurable to do what you're showing just using the dialogs.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.