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)
  • 2
    Wouldn't a normal SharePoint View satisfy your requirements? Commented Dec 10, 2009 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
    Commented Dec 10, 2009 at 9:15

2 Answers 2


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? :)

  • Cool, question answered!
    – George2
    Commented Dec 10, 2009 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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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