Problem for filtering a list
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
Problem for filtering a list

 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development
Author Message
Eric
Guest





Posted: Tue Jan 11, 2005 7:56 pm    Post subject: Problem for filtering a list Reply with quote

Hi all,

I have a list named Permissions in an area QuickLinks located under the
HomeArea.
This list contains at least 3 columns (LinkTitle, Country, Groups)
There are 2 rows in this list :
LinkTitle Country Groups
1 Worldwide SPS_WW
2 Local France SPS_FR

I want to select a precise row of my list, so I have written the following
Webpart :
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;

using System.Drawing;
using Microsoft.SharePoint.Portal.UserProfiles;
using Microsoft.SharePoint.Portal.SiteData;
using System.Data;
using System.Collections.Specialized;
using System.Security.Principal;
using Microsoft.SharePoint.Portal;

namespace MyWebParts
{
/// <summary>
/// Description for OutlookMyContacts.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:OutlookMyContacts
runat=server></{0}:OutlookMyContacts>"),
XmlRoot(Namespace="MyWebParts")]
public class OutlookMyContacts : Microsoft.SharePoint.WebPartPages.WebPart
{
private const string defaultText = "";

private string text = defaultText;

[Browsable(true),
Category("Miscellaneous"),
DefaultValue(defaultText),
WebPartStorage(Storage.Personal),
FriendlyName("Text"),
Description("Text Property")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}


/// <summary>
/// Render this Web Part to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void RenderWebPart(HtmlTextWriter output)
{
Label lbl = new Label();
string retour = "";
SPQuery EqQuery = new SPQuery();
EqQuery.Query = "<Where><Eq><FieldRef Name='Country'></FieldRef><Value
Type='Text'>France</Value></Eq></Where>";

PortalContext myPortalContext = PortalApplication.GetContext(Context);
//get homeArea object
Area HomeArea = AreaManager.GetArea(myPortalContext,
AreaManager.GetSystemAreaGuid(myPortalContext, SystemArea.Home));
SPList oList = HomeArea.Areas["QuickLinks"].Web.Lists["Permissions"];
SPListItemCollection splc = oList.GetItems(EqQuery) ;

lbl.Text = "nb lignes dans la liste Permissions : " + splc.Count;
lbl.Text += "condition : " + EqQuery.Query;
foreach(SPListItem li in splc)
lbl.Text += "<br>" + li["LinkTitle"].ToString() + " => " +
li["Groups"].ToString();
if (splc.List.ItemCount == 1)
retour = splc.List.Items[0]["Groups"].ToString();
else
retour = "";

output.Write(SPEncode.HtmlEncode(retour));
lbl.RenderControl(output);
}
}
}


When I run this whatever is the query I always get all the rows of my
list!!!!

If some of you could help me, I'm getting mad with this problem!!!

Thanks
Eric.
Back to top
Mike Walsh
Guest





Posted: Wed Jan 12, 2005 12:14 pm    Post subject: Re: Problem for filtering a list Reply with quote

Please do not post questions on writing or amending web parts (even as an
additional newsgroup) to the main WSS newsgroup.

These questions are precisely what the .development newsgroup has been
created for.

Let's keep these things separate to the benefit of all.

[I would also suggest that you make your mind up whether this is a WSS
problem or a SPS 2003 problem and then send to only ONE development
newsgroup too]

Follow-ups to the WSS development newsgroup.

Will people responding to the original post please remove the main WSS
newsgroup from the list of newsgroups.

Thanks.

Mike Walsh, Helsinki, Finland
WSS FAQ at http://wss.collutions.com
Please post questions to the newsgroup only.


"Eric" <eric.holtzmann_nospam@capgemini.nospam.com> wrote in message
news:efvEUV%239EHA.2996@TK2MSFTNGP10.phx.gbl...
Quote:
Hi all,

I have a list named Permissions in an area QuickLinks located under
the
HomeArea.
This list contains at least 3 columns (LinkTitle, Country, Groups)
There are 2 rows in this list :
LinkTitle Country Groups
1 Worldwide SPS_WW
2 Local France SPS_FR

I want to select a precise row of my list, so I have written the following
Webpart :
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;

using System.Drawing;
using Microsoft.SharePoint.Portal.UserProfiles;
using Microsoft.SharePoint.Portal.SiteData;
using System.Data;
using System.Collections.Specialized;
using System.Security.Principal;
using Microsoft.SharePoint.Portal;

namespace MyWebParts
{
/// <summary
/// Description for OutlookMyContacts.
/// </summary
[DefaultProperty("Text"),
ToolboxData("<{0}:OutlookMyContacts
runat=server></{0}:OutlookMyContacts>"),
XmlRoot(Namespace="MyWebParts")]
public class OutlookMyContacts :
Microsoft.SharePoint.WebPartPages.WebPart
{
private const string defaultText = "";

private string text = defaultText;

[Browsable(true),
Category("Miscellaneous"),
DefaultValue(defaultText),
WebPartStorage(Storage.Personal),
FriendlyName("Text"),
Description("Text Property")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}


/// <summary
/// Render this Web Part to the output parameter specified.
/// </summary
/// <param name="output"> The HTML writer to write out to </param
protected override void RenderWebPart(HtmlTextWriter output)
{
Label lbl = new Label();
string retour = "";
SPQuery EqQuery = new SPQuery();
EqQuery.Query = "<Where><Eq><FieldRef Name='Country'></FieldRef><Value
Type='Text'>France</Value></Eq></Where>";

PortalContext myPortalContext = PortalApplication.GetContext(Context);
//get homeArea object
Area HomeArea = AreaManager.GetArea(myPortalContext,
AreaManager.GetSystemAreaGuid(myPortalContext, SystemArea.Home));
SPList oList = HomeArea.Areas["QuickLinks"].Web.Lists["Permissions"];
SPListItemCollection splc = oList.GetItems(EqQuery) ;

lbl.Text = "nb lignes dans la liste Permissions : " + splc.Count;
lbl.Text += "condition : " + EqQuery.Query;
foreach(SPListItem li in splc)
lbl.Text += "<br>" + li["LinkTitle"].ToString() + " => " +
li["Groups"].ToString();
if (splc.List.ItemCount == 1)
retour = splc.List.Items[0]["Groups"].ToString();
else
retour = "";

output.Write(SPEncode.HtmlEncode(retour));
lbl.RenderControl(output);
}
}
}


When I run this whatever is the query I always get all the rows of my
list!!!!

If some of you could help me, I'm getting mad with this problem!!!

Thanks
Eric.

Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB