Question

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?

EDIT1:

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)
            {
                writer.Write(oListItem["Department"].ToString()+"###");
            } 
Was it helpful?

Solution

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

OTHER TIPS

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.

M.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top