Please help me to sort out this issue

ramesh perera asked on October 6, 2016 14:39

Hi! I have following code and i need to set order by according to 'ToolNoFirstPart,ToolNoSecondPart'. how i can do that? please help

var oSearchRows = oStockDs.Tables[0].AsEnumerable() .Select(rt => {

                        CMS.DocumentEngine.TreeNode oNodeIn = GetNodeFromSearchResultsRow(rt["id"].ToString());

                        SKUInfo oSkuIn = SKUInfoProvider.GetSKUInfo(oNodeIn.NodeSKUID);

                        if (oSkuIn.SKUEnabled && !oNodeIn.GetBooleanValue("DocumentMenuItemHideInNavigation", true))
                        {
                            return rt;
                        }
                        else
                        {
                            return null;
                        }
                    }
                ).OrderBy(ord => {
                    CMS.DocumentEngine.TreeNode oNodeInfo = GetNodeFromSearchResultsRow(ord["id"].ToString());
                    SKUInfo oSkuInfo = SKUInfoProvider.GetSKUInfo(oNodeInfo.NodeSKUID);
                    string ToolNoFirstPart = "";
                    string ToolNoSecondPart = "";

                    if (oSkuInfo != null)
                    {
                        string ToolNo = ValidationHelper.GetString(oSkuInfo["skuNumber"], "");


                        string[] splitToolNo = ToolNo.Split(' ');
                        if (splitToolNo.Length > 0)
                        {
                            ToolNoFirstPart = splitToolNo[0];
                            ToolNoSecondPart = splitToolNo[1];
                        }
                    }
                    return "";
                }   
                ).OfType<DataRow>();

                //DataTable oDataTable = oSearchRows.Where(rt => (rt != null)).CopyToDataTable(); 
                DataTable oDataTable = oSearchRows.CopyToDataTable(); 

Recent Answers


Roman Hutnyk answered on October 6, 2016 16:02

Ramesh,

It is not what data structure your select returns. However normally I'd order collection as following:

DocumentHelper.GetDocuments().OrderBy(d => new { d.DocumentName, d.DocumentPriority });

So currently your Order statement returns empty string:

return "";

I'd substitute it with this:

return new {ToolNoFirstPart, ToolNoSecondPart };

2 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.