What is the best way to retrieve distinct / unique values using SPQuery?

前端 未结 6 966
孤独总比滥情好
孤独总比滥情好 2020-12-30 04:03

I have a list that looks like:

Movie          Year
-----          ----
Fight Club     1999
The Matrix     1999
Pulp Fiction   1994

Using CA

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-30 04:54

    There is no DISTINCT in CAML to populate your dropdown try using something like:

    foreach (SPListItem listItem in listItems)
        {
            if ( null == ddlYear.Items.FindByText(listItem["Year"].ToString()) )
           {
                       ListItem ThisItem = new ListItem();
                       ThisItem.Text = listItem["Year"].ToString();
                       ThisItem.Value = listItem["Year"].ToString();
                       ddlYear.Items.Add(ThisItem);
            }
       }
    

    Assumes your dropdown is called ddlYear.

提交回复
热议问题