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;
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
add a comment |
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
add a comment |
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
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
c# asp.net list sorting listview
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
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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();
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
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
add a comment |
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();
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
add a comment |
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();
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();
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
add a comment |
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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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