Eric
Guest
|
Posted:
Tue Jan 11, 2005 7:56 pm Post subject:
Problem for filtering a list |
|
|
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. |
|
Mike Walsh
Guest
|
Posted:
Wed Jan 12, 2005 12:14 pm Post subject:
Re: Problem for filtering a list |
|
|
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.
|
|
|