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 ClientObjectModel (C#) to retreive data from a custom list, which is structured like this:

ListStructure

What i need is some kind of "select distinct" which retreives only the categories, without duplicates:

cat1; cat2; cat3;

Im not able to find a way with CAML, and iterating through all items is not an option (the list contains 6000 items, to load each of them is very slow). Is there any other way I dont know?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Literally CAML query even in SharePoint 2013 doesn't have distinct function you can use, however I find this code that can help you,

 protected void btn_binddropdown_Click(object sender, EventArgs e)
        {
            try
            {
                SPList oList = SPContext.Current.Web.Lists["CAMLTEST"];
                SPQuery query = new SPQuery();
                query.Query = "<OrderBy><FieldRef Name='Name' /></OrderBy>";
                DataTable dtcamltest = oList.GetItems(query).GetDataTable();
                DataView dtview = new DataView(dtcamltest);
                DataTable dtdistinct = dtview.ToTable(true, "Name");
                ddl_names.DataSource = dtdistinct; 
                ddl_names.DataTextField = "Name";
                ddl_names.DataValueField = "Name";
                ddl_names.DataBind();                           



            }
            catch (Exception exe)
            {
                Response.Write("Exception at btn_binddropdown_Click :" + exe);
            }
       }

enter image description here

Source

If nothing works then you still have choice of Custom web services or use jQuery or JS to select distinct list items,

http://stackoverflow.com/questions/560550/what-is-the-best-way-to-retrieve-distinct-unique-values-using-spquery

Possible to get distinct values from GetListItems?

How to retrieve distinct values with JavaScript Client Object Model

share|improve this answer

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.