0
votes

I have created a template Location Chart Template having two fields given below:

Field 1-->
Name: Value
DataType: Integer
Field 2-->
Name: CP_Value
DataType: Integer

Now I have created a folder Location Chart List under sitecore content node and under this folder I have added 5 items with it's values(i.e. values showns below entered in Value field NOT in CP_Value field ):

East-5
Midwest-11
South-13
West-2
International-9

Now I want to fetch these location items collection on Sample.aspx page via ajax call and write down the following code in code behind file:

List<Item> locationChartsDesc = new List<Item>();
var valueFieldName = "Value" //Value OR CP_Value
var parentItem = SampleSitecoreHelper.GetItemByPath("/sitecore/content/Global Items/Location Chart List");
List<Item> locChild = new List<Item>();
if (valueFieldName != string.Empty)
{
 locationChartsDesc = parentItem.GetChildren().OrderByDescending(x => x.Fields[valueFieldName].Value).ToList();
}

The sequence of Item at this step I'm getting is:

International-9
East-5
West-2
South-13
Midwest-11

Which is wrong

The sequence of Item at this step must be:

South-13
Midwest-11
International-9
East-5
West-2

Is there anything wrong in this code?

Thanks

1

1 Answers

0
votes

I got the answer.I have to do the following:

Convert.ToInt16(x.Fields[valueFieldName].Value)