In this post we are going to see how we can get the unique values from a specific field from SharePoint list.
Method is very simple. All you have to do is use this code and you can get the distinct values from list field.
SPList list = SPContext.Current.Web.Lists[lstGUID];
SPField field = list.Fields.GetField("OrderDate"); //OrderDate is date field. Replace with the field that you want to get unique value of.
object[,] values;
uint numberValues = list.GetDistinctFieldValues(field, out values);
for (int i = 0; i < numberValues; i++)
{
lblValues.Text += values.GetValue(0, i).ToString() + "
";
}
Variables and labels are used only for reference.
GetDistinctFieldValues is a method which gives us unique values that gets stored in the object array which you can iterate and can get the values.
However this method is obsolete. but just in case this can becomes a day saver some time.
Method is very simple. All you have to do is use this code and you can get the distinct values from list field.
SPList list = SPContext.Current.Web.Lists[lstGUID];
SPField field = list.Fields.GetField("OrderDate"); //OrderDate is date field. Replace with the field that you want to get unique value of.
object[,] values;
uint numberValues = list.GetDistinctFieldValues(field, out values);
for (int i = 0; i < numberValues; i++)
{
lblValues.Text += values.GetValue(0, i).ToString() + "
";
}
Variables and labels are used only for reference.
GetDistinctFieldValues is a method which gives us unique values that gets stored in the object array which you can iterate and can get the values.
However this method is obsolete. but just in case this can becomes a day saver some time.
No comments:
Post a Comment