How to filter a list on SharePoint

George2
  • How to filter a list on SharePoint George2

    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()+"###");
                } 
    

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

  • 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.

Related questions and answers
  • I am using Microsoft Search Server 2008 (based on SharePoint Server 2007) + C# + .Net 3.5 + VSTS 2008 + ASP.Net to develop a web application which invokes Search Server 2008 Web Services when a button in the html page is pressed. I am using the following code to query content from Microsoft Search Server 2008. My question is how to display the search results from the DataSet retrieved? I did... = "Microsoft"; //The XML string containing the query request information //for the Web service string qXMLString = "&lt;QueryPacket xmlns='urn:Microsoft.Search.Query'&gt

  • So I did create on an SPWeb 20 custom lists and then a tasks list. For each of those 20 lists I've created 20 site lookup columns. I then created 20 Content Types based on Task content type. Then I've added each content type to the Tasks list. After that I've added each lookup site column to the corresponding list content type. So far so good. I've built a custom WebPart that displays task items using ListViewByQuery control. Here is how an SPQuery looks: &lt;Query> &lt;Where> &lt;Eq> &lt;FieldRef Name='Relaterat_x0020_till_x0020_avtal' LookupId='TRUE

  • Has anybody upgraded an old custom field type to use the new XSL transform in SharePoint 2010? I have a multi-column field type, and want the Display pattern to render the 2nd "column", which..., but that ends up rendering the actual anchor tag, as opposed to a clickable hyperlink: &lt;a href="http://www.something.com"&gt;www.something.com&lt;/a> So then I tried creating a XSL transform, since that is supposed to be the new and improved way of doing this. Unfortunately, I can't get that to work either. I am getting the same thing I got using the RenderPattern. I'm no XSL expert, so can anyone

  • Hello I really need help with this... , I am using Sharepoint 2007. I have the 'collect data from user' action in a workflow - which generates a custom form within the workflow folder. The form... on this? I have pasted the form's DataFormWebPart below for reference: Many Thanks! &lt;WebPartPages:DataFormWebPart runat="server" IsIncluded="True" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="0...;DataSources> &lt;SharePoint:SPDataSource runat="server" DataSourceMode="ListItem" UseInternalName="true" selectcommand="&lt;View&gt;&lt;ViewFields&gt;&lt;FieldRef Name

  • Possible Duplicate: How to use JavaScript and CSS in a web part? I am using SharePoint Server 2007 Enterprise with Windows Server 2008 Enterprise. I am developing using VSTS 2008 + C# + .Net 3.5 + ASP.Net. I have the following code which works correctly in ASP.Net (aspx) and I want to implement the same function in a WebPart and deploy into a page of SharePoint publishing portal site. Any ideas how to implement? My major confusion is how to deal with the code in the head part of the following code? Any reference code or document? Here is the aspx code I am using, &lt;!doctype

  • . Scoped to Site. Registration: contains a ListTemplate and a ListInstance that just modifies a basic Custom List to enable content types and add my custom content type. Scoped to Web. Here's what's...), the list form suddenly works correctly. This makes me think there's something wrong with my content type. Here's what I'm working with. Some names have been changed to protect the innocent. &lt;ContentType... xmlns:ows="Microsoft SharePoint" Title="Withdrawals" FolderCreation="FALSE" Direction="LTR" Url="Lists/Withdrawals" EnableContentTypes="TRUE" BaseType="0"&gt; &lt;MetaData> &lt;ContentTypes>

  • (I have also asked this question on Stack Overflow) I have a SharePoint feature I'm using to add some custom aspx files to the Pages Library. When I activate the feature, I can visit the pages in-browser and they are visible in SPDesigner, but when I "View All Site Content" they are not there. Why is this the case? The Feature's Elements File: &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Elements Id="9e85eb79-6d8d-4ff3-b0d4-64d55c3bb577" xmlns="http://schemas.microsoft.com/sharepoint/"&gt; &lt;Module Name="Pages" Url="Pages"&gt; &lt;File Path="Example.aspx" Url

  • Hiding Left Nav user1155

    ; &lt;/tr> &lt;/table> &lt;/asp:ContentPlaceholder> On the pagelayouts I don't want this on I have this: &lt;asp:Content ContentPlaceHolderId="LeftNavTableCell" runat="server"&gt...-quickLaunch"&gt; &lt;asp:ContentPlaceHolder id="PlaceHolderQuickLaunchTop" runat="server"&gt; &lt;SharePoint:UIVersionedContent UIVersion="3" runat="server"&gt; &lt;ContentTemplate> &lt;h3 class="ms-standardheader"&gt;&lt;label class="ms-hidden"&gt;&lt;SharePoint:EncodedLiteral runat="server" text="&lt;%$Resources:wss,quiklnch_pagetitle

  • I am using SharePoint Server 2007 Enterprise with Windows Server 2003 R2 Enterprise. I am developing using VSTS 2008 + C# + .Net 3.5 + IIS 6.0. I have put a simple aspx page into layout folder... manager. I am not in Active Directory or Windows domain environment. I have enabled permission to anonymous users for the whole SharePoint site. Any ideas what is wrong? &lt;%@ Page Language="C#" AutoEventWireup="true" %&gt; &lt;script runat="server" type="text/C#"&gt; protected void Page_Load(object sender,EventArgs e) { Response.Redirect("http://www.google.com"); } &lt;/script> &lt

Data information