Link to home
Start Free TrialLog in
Avatar of suresh pondicherry
suresh pondicherryFlag for United States of America

asked on

linqtosql order by string with numbers

Hi ,
Thanks !
Am using linqtosql and C#.

Have attached the screen shot of the datasource .
I need to order the list by name,  (Screen shot is attached ) but name is alphanumeric string. Each record under name starts with section ??:  i.e. Section 12 : test
                          Section 11: test
                          Section 00: test


I need to order by name by sort through numbers which you see  within the string


Expected output:
=============
{Folderkey=27, Name="Section1:Underwriting"}
{Folderkey=25, Name="Section2:Third-Parth Reports"}
{Folderkey=4, Name="Section3:Borrower"}

code:
public ActionResult FolderRearrangePopupLoad(Guid taskInstanceId, string Model)
        {
            var nums = "0123456789".ToCharArray();//skumar:20180104 for task#
            var reordermodel = new FileReorderModel { TaskInstanceId = taskInstanceId };

            var FileList = (from filelist in taskManager.GetAllTaskFileByTaskInstanceId(taskInstanceId)
                            select new
                            {
                                filelist.TaskFileId,
                                Name = filelist.FileName

                            });

            ViewBag.FileList = FileList;


            var folderlist = (from folders in appProcessManager.GetFolderbyViewId(1)
                              orderby folders.FolderName.LastIndexOfAny(nums)
                              orderby folders.FolderName
                              select new
                              {
                                  folders.FolderKey,
                                  Name = folders.FolderName

                              });
            ViewBag.FromFolder = new SelectList(folderlist, "FolderKey", "Name");

Open in new window


Kind regards,
Suresh
Folder-list.PNG
Avatar of suresh pondicherry
suresh pondicherry
Flag of United States of America image

ASKER

Hi,
Please find the screen shot. don't know why 00 is coming after 9 instead that appears at the top.

Kind regards,
Pooja
test1.PNG
I got the solution. I would like to close the question
Please let me know if i need to improve in asking questions or what should i add on top on original question to make it more clear. Just curious why i am not getting any response for several questions.
Avatar of louisfr
louisfr

I cannot speak for others, but in my case, I didn't answer because you asked the question at the end of my workday yesterday and it's now the start of my next workday.

Could you post your solution ? It can help other people trying to do the same thing.
ASKER CERTIFIED SOLUTION
Avatar of suresh pondicherry
suresh pondicherry
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial