Distinct Values in Filter Dropdown(Distinct Sharpoint List Column Value)

Questions:

I'm trying to do something that should be simple but does not appear to be in practise.

I have a simple sharepoint list. I added 4 entries, one of the columns is "Country"
Next, I created an aspx page in Sharepoint Designer to display the values in a table.

I added a DataSource based on the list and then a drop down control, populating it with the "Country" values... however I can not get rid of the non-unique values.
This was to be my Country Filter

I have 4 items, 3 have Ireland, 1 have the UK, I get 3 Irelands and a UK in my list. While you can sort the values, there does not appear to be anyway to tell sharepoint to just display distinct values.

If this was asp.net and a sql server you would simply do a "select distinct... " query.

 

string

 

siteUrl = "http://" + Request.Url.Host + ":" + Request.Url.Port + "/" + _lang + "/";

 

SPSite spSiteCollection = new SPSite(siteUrl);

 

SPWeb currentWeb = spSiteCollection.RootWeb;

 

SPListcurrentList=this.CurrentWeb.Lists[this.ListName];

SPFieldCollectionlistFields=currentList.Fields;
SortedListslSortedList=newSortedList();
 
foreach(SPFieldfieldinlistFields)
{
if(field.Sortable&&!field.Hidden)
{
if(!slSortedList.ContainsKey(field.Title))
{
slSortedList.Add(field.Title,field.InternalName);
}
}
}
 
ddlSRSortField1.DataSource=slSortedList;
ddlSRSortField1.DataTextField="Key";
ddlSRSortField1.DataValueField="Value";

ddlSRSortField1.DataBind();

 

 

 

I tried using CAML Query...here using Datatable distinct list items were selected.

public DataView DistinctProjectItem(string listName,string fieldName)
    {
        siteUrl = ConfigurationManager.AppSettings["siteUrl"].ToString();
        SPSite spSite = new SPSite(siteUrl);
        SPWeb spWeb = spSite.OpenWeb();
        using (spWeb = spSite.OpenWeb())
        {
            SPList MyList = spWeb.Lists["Employee Log"];
            SPListItemCollection spListItem;
            SPQuery spDistinctItem = new SPQuery();
            spDistinctItem.Query = "<OrderBy><FieldRef Name='Projects'/></Order By><FieldRef Name='"+fieldName+"'/>";
            spListItem = MyList.GetItems(spDistinctItem);

            DataTable dtDistinctProject = spListItem.GetDataTable();

            try
            {
                DataTable dtListItem = dtDistinctProject.DefaultView.ToTable(true, fieldName);//true means selecting distince items
                DataView dvListItem = new DataView(dtListItem);
                return(dvListItem);
            }
            catch
            {
                DataView dvListItemEmpty = null;
                return (dvListItemEmpty);
            }
        }
    }

reference:

http://www.sharepointdev.net/sharepoint--design-customization/distinct-values-in-filter-dropdown-9960.shtml

 

http://social.msdn.microsoft.com/forums/en-US/sharepointcustomization/thread/9b2464fc-1255-431e-8976-f4c9e44ec256/

 

 

http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/a2c6bed0-eee1-4f9b-b468-fc57c2e45c16

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值