3
votes

I have a problem in sharepoint webpart. I have a custom list where in I have a column name order with type number. then I created a webpart that display the list and sorted by the column order.

I have this caml query
string test =
<Query> +
   <OrderBy> +
      <FieldRef Name='order0' Ascending='True' /> +
   </OrderBy> +
</Query>;

my problem is when I loop like this sample

foreach (SPListItem result in items) { ..... }

the result will always be like this:
4
1
2
3

where I want to have like this:
1
2
3
4

Please I really need your help. I'm really new in sharepoint and I don't have a training for this.

Thanks,
Gracela

2

2 Answers

1
votes

Your query looks OK, it should work.

The only possibility I see is that the field 'order0' that you sort by is not the field with the numbers.

-1
votes

Very late, but this could help out someone else. In my case, my column was configured Sortable=FALSE. We were deploying it via feature/caml. So this may be the cause of it.

It is easy to see if this is your issue, simply try sorting the column in the list, you will see in the column header the message

This column type cannot be sorted