Sorting values consisting of chars and numbers in an List<Tuple>() or asp:ListViewHow do I sort a list of dictionaries by a value of the dictionary?Sort a Map<Key, Value> by valuesHow to sort a list of objects based on an attribute of the objects?How do I sort a dictionary by value?What's the difference between lists and tuples?Sort array of objects by string property valueHow do I get the number of elements in a list?How to Sort Multi-dimensional Array by Value?How to sort (list/tuple) of lists/tuples by the element at a given index?How to Sort a List<T> by a property in the object

Replace from the current position to the end of the line

Would a carnivorous diet be able to support a giant worm?

Why don't we give Peah today?

How do you move up one folder in Finder?

Is there a strong legal guarantee that the U.S. can give to another country that it won't attack them?

Is system.schedule(...) @AuraEnabled?

Were Pandaria, Broken Isles, Northrend, Kul'Tiras and Zandalar also affected by the Cataclysm?

What would +1/+2/+3 items be called in game?

Integer Lists of Noah

What is the parallel of Day of the Dead with Stranger things?

What could cause the sea level to massively decrease?

What adjective means "accurately representitive of reality"?

What happens when adult Billy Batson says "Shazam"?

Why different specifications for telescopes and binoculars?

When an electron changes its spin, or any other intrinsic property, is it still the same electron?

How do we handle pauses in a dialogue?

How was the Shuttle loaded and unloaded from its carrier aircraft?

Why does the US seem to have a rather low economic interest in Africa?

Is it ok for parents to kiss and romance with each other while their 2- to 8-year-old child watches?

Are there any sports for which the world's best player is female?

Write a function

What are some further readings in Econometrics you recommend?

When I press the space bar it deletes the letters in front of it

AWS Fargate + Application Load Balancer SSL Termination



Sorting values consisting of chars and numbers in an List>() or asp:ListView


How do I sort a list of dictionaries by a value of the dictionary?Sort a Map<Key, Value> by valuesHow to sort a list of objects based on an attribute of the objects?How do I sort a dictionary by value?What's the difference between lists and tuples?Sort array of objects by string property valueHow do I get the number of elements in a list?How to Sort Multi-dimensional Array by Value?How to sort (list/tuple) of lists/tuples by the element at a given index?How to Sort a List<T> by a property in the object






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have an Tuple List and I'm filling this list with all directorys of an folder and bind it to an asp:ListView with this code:



List<string> directoryContent = new List<string>(Directory.GetFileSystemEntries(dirPath);
List<Tuple<string, string>> directoryList = new List<Tuple<string, string>>();

for (int i = 0; i < directoryContent.Count; i++)

FileAttributes attr = File.GetAttributes(directoryContent[i]);
if (attr.ToString().Equals("Directory"))

String str = directoryContent[i].Remove(0, dirPath.Length);
string count = Directory.GetFiles(directoryContent[i], "*.*", SearchOption.AllDirectories).Length.ToString();
directoryList.Add(new Tuple<string, string>(str, count));



directoryListView.DataSource = directoryList;
directoryListView.DataBind();


For example the found directories are



  • 12

  • 566

  • 10001

  • 10

  • templates

  • files

What would be the best way to sort the List or the ListView in this way? Thank you in advance.
I need to sort the directory that they are sorted in this order:



  • files

  • templates

  • 10

  • 12

  • 566

  • 1001









share|improve this question






























    0















    I have an Tuple List and I'm filling this list with all directorys of an folder and bind it to an asp:ListView with this code:



    List<string> directoryContent = new List<string>(Directory.GetFileSystemEntries(dirPath);
    List<Tuple<string, string>> directoryList = new List<Tuple<string, string>>();

    for (int i = 0; i < directoryContent.Count; i++)

    FileAttributes attr = File.GetAttributes(directoryContent[i]);
    if (attr.ToString().Equals("Directory"))

    String str = directoryContent[i].Remove(0, dirPath.Length);
    string count = Directory.GetFiles(directoryContent[i], "*.*", SearchOption.AllDirectories).Length.ToString();
    directoryList.Add(new Tuple<string, string>(str, count));



    directoryListView.DataSource = directoryList;
    directoryListView.DataBind();


    For example the found directories are



    • 12

    • 566

    • 10001

    • 10

    • templates

    • files

    What would be the best way to sort the List or the ListView in this way? Thank you in advance.
    I need to sort the directory that they are sorted in this order:



    • files

    • templates

    • 10

    • 12

    • 566

    • 1001









    share|improve this question


























      0












      0








      0








      I have an Tuple List and I'm filling this list with all directorys of an folder and bind it to an asp:ListView with this code:



      List<string> directoryContent = new List<string>(Directory.GetFileSystemEntries(dirPath);
      List<Tuple<string, string>> directoryList = new List<Tuple<string, string>>();

      for (int i = 0; i < directoryContent.Count; i++)

      FileAttributes attr = File.GetAttributes(directoryContent[i]);
      if (attr.ToString().Equals("Directory"))

      String str = directoryContent[i].Remove(0, dirPath.Length);
      string count = Directory.GetFiles(directoryContent[i], "*.*", SearchOption.AllDirectories).Length.ToString();
      directoryList.Add(new Tuple<string, string>(str, count));



      directoryListView.DataSource = directoryList;
      directoryListView.DataBind();


      For example the found directories are



      • 12

      • 566

      • 10001

      • 10

      • templates

      • files

      What would be the best way to sort the List or the ListView in this way? Thank you in advance.
      I need to sort the directory that they are sorted in this order:



      • files

      • templates

      • 10

      • 12

      • 566

      • 1001









      share|improve this question
















      I have an Tuple List and I'm filling this list with all directorys of an folder and bind it to an asp:ListView with this code:



      List<string> directoryContent = new List<string>(Directory.GetFileSystemEntries(dirPath);
      List<Tuple<string, string>> directoryList = new List<Tuple<string, string>>();

      for (int i = 0; i < directoryContent.Count; i++)

      FileAttributes attr = File.GetAttributes(directoryContent[i]);
      if (attr.ToString().Equals("Directory"))

      String str = directoryContent[i].Remove(0, dirPath.Length);
      string count = Directory.GetFiles(directoryContent[i], "*.*", SearchOption.AllDirectories).Length.ToString();
      directoryList.Add(new Tuple<string, string>(str, count));



      directoryListView.DataSource = directoryList;
      directoryListView.DataBind();


      For example the found directories are



      • 12

      • 566

      • 10001

      • 10

      • templates

      • files

      What would be the best way to sort the List or the ListView in this way? Thank you in advance.
      I need to sort the directory that they are sorted in this order:



      • files

      • templates

      • 10

      • 12

      • 566

      • 1001






      c# asp.net list sorting listview






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 9:43









      VDWWD

      25.9k13 gold badges39 silver badges58 bronze badges




      25.9k13 gold badges39 silver badges58 bronze badges










      asked Mar 26 at 0:20









      raven_977raven_977

      1201 gold badge2 silver badges17 bronze badges




      1201 gold badge2 silver badges17 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You can use Linq for that.



          //test data
          List<string> list = new List<string>()

          "12",
          "566",
          "10001",
          "10",
          "templates",
          "files"
          ;

          int tempInt;

          //filter the numbers from the list and sort
          var listNumbers = list.Where(x => int.TryParse(x, out tempInt)).Select(y => Convert.ToInt32(y)).OrderBy(z => z);

          //filter the strings from the list and sort
          var listStrings = list.Where(x => !int.TryParse(x, out tempInt)).OrderBy(y => y);

          //join the two lists again
          var orderedList = listStrings.Concat(listNumbers.Select(y => y.ToString())).ToList();


          Update for Tuple List



          List<Tuple<string, string>> list = new List<Tuple<string, string>>()

          new Tuple<string, string>("12", "NA"),
          new Tuple<string, string>("566", "NA"),
          new Tuple<string, string>("10001", "NA"),
          new Tuple<string, string>("10", "NA"),
          new Tuple<string, string>("templates", "NA"),
          new Tuple<string, string>("files", "NA")
          ;

          int tempInt;

          //filter the numbers from the list and sort
          var listNumbers = list.Where(x => int.TryParse(x.Item1, out tempInt)).Select(y => new Tuple<int, string>(Convert.ToInt32(y.Item1), y.Item2)).OrderBy(z => z.Item1);

          //filter the strings from the list and sort
          var listStrings = list.Where(x => !int.TryParse(x.Item1, out tempInt)).OrderBy(z => z.Item1);

          //join the two lists again
          var orderedList = listStrings.Concat(listNumbers.Select(y => new Tuple<string, string>(y.Item1.ToString(), y.Item2))).ToList();





          share|improve this answer

























          • Thank you, this works fantastic with List<> but I do have a Tuple List. Sorry that I did not write it more specific in my example. Do you know an similar solution working with tuples, too?

            – raven_977
            Mar 26 at 23:58











          • Updated my answer

            – VDWWD
            Mar 27 at 9:42











          • this is fantastic, thank you very very very much!!!

            – raven_977
            Mar 27 at 22:20










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348185%2fsorting-values-consisting-of-chars-and-numbers-in-an-listtuple-or-asplist%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can use Linq for that.



          //test data
          List<string> list = new List<string>()

          "12",
          "566",
          "10001",
          "10",
          "templates",
          "files"
          ;

          int tempInt;

          //filter the numbers from the list and sort
          var listNumbers = list.Where(x => int.TryParse(x, out tempInt)).Select(y => Convert.ToInt32(y)).OrderBy(z => z);

          //filter the strings from the list and sort
          var listStrings = list.Where(x => !int.TryParse(x, out tempInt)).OrderBy(y => y);

          //join the two lists again
          var orderedList = listStrings.Concat(listNumbers.Select(y => y.ToString())).ToList();


          Update for Tuple List



          List<Tuple<string, string>> list = new List<Tuple<string, string>>()

          new Tuple<string, string>("12", "NA"),
          new Tuple<string, string>("566", "NA"),
          new Tuple<string, string>("10001", "NA"),
          new Tuple<string, string>("10", "NA"),
          new Tuple<string, string>("templates", "NA"),
          new Tuple<string, string>("files", "NA")
          ;

          int tempInt;

          //filter the numbers from the list and sort
          var listNumbers = list.Where(x => int.TryParse(x.Item1, out tempInt)).Select(y => new Tuple<int, string>(Convert.ToInt32(y.Item1), y.Item2)).OrderBy(z => z.Item1);

          //filter the strings from the list and sort
          var listStrings = list.Where(x => !int.TryParse(x.Item1, out tempInt)).OrderBy(z => z.Item1);

          //join the two lists again
          var orderedList = listStrings.Concat(listNumbers.Select(y => new Tuple<string, string>(y.Item1.ToString(), y.Item2))).ToList();





          share|improve this answer

























          • Thank you, this works fantastic with List<> but I do have a Tuple List. Sorry that I did not write it more specific in my example. Do you know an similar solution working with tuples, too?

            – raven_977
            Mar 26 at 23:58











          • Updated my answer

            – VDWWD
            Mar 27 at 9:42











          • this is fantastic, thank you very very very much!!!

            – raven_977
            Mar 27 at 22:20















          1














          You can use Linq for that.



          //test data
          List<string> list = new List<string>()

          "12",
          "566",
          "10001",
          "10",
          "templates",
          "files"
          ;

          int tempInt;

          //filter the numbers from the list and sort
          var listNumbers = list.Where(x => int.TryParse(x, out tempInt)).Select(y => Convert.ToInt32(y)).OrderBy(z => z);

          //filter the strings from the list and sort
          var listStrings = list.Where(x => !int.TryParse(x, out tempInt)).OrderBy(y => y);

          //join the two lists again
          var orderedList = listStrings.Concat(listNumbers.Select(y => y.ToString())).ToList();


          Update for Tuple List



          List<Tuple<string, string>> list = new List<Tuple<string, string>>()

          new Tuple<string, string>("12", "NA"),
          new Tuple<string, string>("566", "NA"),
          new Tuple<string, string>("10001", "NA"),
          new Tuple<string, string>("10", "NA"),
          new Tuple<string, string>("templates", "NA"),
          new Tuple<string, string>("files", "NA")
          ;

          int tempInt;

          //filter the numbers from the list and sort
          var listNumbers = list.Where(x => int.TryParse(x.Item1, out tempInt)).Select(y => new Tuple<int, string>(Convert.ToInt32(y.Item1), y.Item2)).OrderBy(z => z.Item1);

          //filter the strings from the list and sort
          var listStrings = list.Where(x => !int.TryParse(x.Item1, out tempInt)).OrderBy(z => z.Item1);

          //join the two lists again
          var orderedList = listStrings.Concat(listNumbers.Select(y => new Tuple<string, string>(y.Item1.ToString(), y.Item2))).ToList();





          share|improve this answer

























          • Thank you, this works fantastic with List<> but I do have a Tuple List. Sorry that I did not write it more specific in my example. Do you know an similar solution working with tuples, too?

            – raven_977
            Mar 26 at 23:58











          • Updated my answer

            – VDWWD
            Mar 27 at 9:42











          • this is fantastic, thank you very very very much!!!

            – raven_977
            Mar 27 at 22:20













          1












          1








          1







          You can use Linq for that.



          //test data
          List<string> list = new List<string>()

          "12",
          "566",
          "10001",
          "10",
          "templates",
          "files"
          ;

          int tempInt;

          //filter the numbers from the list and sort
          var listNumbers = list.Where(x => int.TryParse(x, out tempInt)).Select(y => Convert.ToInt32(y)).OrderBy(z => z);

          //filter the strings from the list and sort
          var listStrings = list.Where(x => !int.TryParse(x, out tempInt)).OrderBy(y => y);

          //join the two lists again
          var orderedList = listStrings.Concat(listNumbers.Select(y => y.ToString())).ToList();


          Update for Tuple List



          List<Tuple<string, string>> list = new List<Tuple<string, string>>()

          new Tuple<string, string>("12", "NA"),
          new Tuple<string, string>("566", "NA"),
          new Tuple<string, string>("10001", "NA"),
          new Tuple<string, string>("10", "NA"),
          new Tuple<string, string>("templates", "NA"),
          new Tuple<string, string>("files", "NA")
          ;

          int tempInt;

          //filter the numbers from the list and sort
          var listNumbers = list.Where(x => int.TryParse(x.Item1, out tempInt)).Select(y => new Tuple<int, string>(Convert.ToInt32(y.Item1), y.Item2)).OrderBy(z => z.Item1);

          //filter the strings from the list and sort
          var listStrings = list.Where(x => !int.TryParse(x.Item1, out tempInt)).OrderBy(z => z.Item1);

          //join the two lists again
          var orderedList = listStrings.Concat(listNumbers.Select(y => new Tuple<string, string>(y.Item1.ToString(), y.Item2))).ToList();





          share|improve this answer















          You can use Linq for that.



          //test data
          List<string> list = new List<string>()

          "12",
          "566",
          "10001",
          "10",
          "templates",
          "files"
          ;

          int tempInt;

          //filter the numbers from the list and sort
          var listNumbers = list.Where(x => int.TryParse(x, out tempInt)).Select(y => Convert.ToInt32(y)).OrderBy(z => z);

          //filter the strings from the list and sort
          var listStrings = list.Where(x => !int.TryParse(x, out tempInt)).OrderBy(y => y);

          //join the two lists again
          var orderedList = listStrings.Concat(listNumbers.Select(y => y.ToString())).ToList();


          Update for Tuple List



          List<Tuple<string, string>> list = new List<Tuple<string, string>>()

          new Tuple<string, string>("12", "NA"),
          new Tuple<string, string>("566", "NA"),
          new Tuple<string, string>("10001", "NA"),
          new Tuple<string, string>("10", "NA"),
          new Tuple<string, string>("templates", "NA"),
          new Tuple<string, string>("files", "NA")
          ;

          int tempInt;

          //filter the numbers from the list and sort
          var listNumbers = list.Where(x => int.TryParse(x.Item1, out tempInt)).Select(y => new Tuple<int, string>(Convert.ToInt32(y.Item1), y.Item2)).OrderBy(z => z.Item1);

          //filter the strings from the list and sort
          var listStrings = list.Where(x => !int.TryParse(x.Item1, out tempInt)).OrderBy(z => z.Item1);

          //join the two lists again
          var orderedList = listStrings.Concat(listNumbers.Select(y => new Tuple<string, string>(y.Item1.ToString(), y.Item2))).ToList();






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 27 at 9:42

























          answered Mar 26 at 7:59









          VDWWDVDWWD

          25.9k13 gold badges39 silver badges58 bronze badges




          25.9k13 gold badges39 silver badges58 bronze badges












          • Thank you, this works fantastic with List<> but I do have a Tuple List. Sorry that I did not write it more specific in my example. Do you know an similar solution working with tuples, too?

            – raven_977
            Mar 26 at 23:58











          • Updated my answer

            – VDWWD
            Mar 27 at 9:42











          • this is fantastic, thank you very very very much!!!

            – raven_977
            Mar 27 at 22:20

















          • Thank you, this works fantastic with List<> but I do have a Tuple List. Sorry that I did not write it more specific in my example. Do you know an similar solution working with tuples, too?

            – raven_977
            Mar 26 at 23:58











          • Updated my answer

            – VDWWD
            Mar 27 at 9:42











          • this is fantastic, thank you very very very much!!!

            – raven_977
            Mar 27 at 22:20
















          Thank you, this works fantastic with List<> but I do have a Tuple List. Sorry that I did not write it more specific in my example. Do you know an similar solution working with tuples, too?

          – raven_977
          Mar 26 at 23:58





          Thank you, this works fantastic with List<> but I do have a Tuple List. Sorry that I did not write it more specific in my example. Do you know an similar solution working with tuples, too?

          – raven_977
          Mar 26 at 23:58













          Updated my answer

          – VDWWD
          Mar 27 at 9:42





          Updated my answer

          – VDWWD
          Mar 27 at 9:42













          this is fantastic, thank you very very very much!!!

          – raven_977
          Mar 27 at 22:20





          this is fantastic, thank you very very very much!!!

          – raven_977
          Mar 27 at 22:20








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348185%2fsorting-values-consisting-of-chars-and-numbers-in-an-listtuple-or-asplist%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

          밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

          1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴