Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using SharePiont 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 retieved 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()+"###");
            } 
share|improve this question
2  
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
add comment

2 Answers

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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.