sorting

What is the best way to sort a data table in ADO.NET

What is the best for sorting a data table in c#, both from a performance and a code-readability point-of-view: personsDT.OrderBy(person => person.PersonName); or: personsDT.DefaultView.Sort = "PersonName ASC"; The personsDT is build from a SharePoint list, so it is impossible to use SQL (I am aware that an ORDER BY claude in a SQL ...

Can I define Default Sort order in LinQ

If I have a nested ListView, and I'm calling a related table in LinQ, how do I sort it, without resorting to the ItemDataBound event of the parent? Pseudo Code (UPDATED WITH SOLUTION): <asp:ListView ID="lv" runat="server" OnItemDataBound="lv_ItemDataBound" > <LayoutTemplate> <!-- Product Category Stuff --> <asp:PlaceHol...

How can I build a std::vector<std::string> and then sort them?

I have a bunch of strings that I need to sort. I think a std::vector would be the easiest way to do this. However, I've never used vectors before and so would like some help. I just need to sort them alphanumerically, nothing special. Indeed, the string::compare function would work. After that, how can I iterate through them to verify ...

jQuery sortable - how to add a sort indicator?

I've successfully implemented the jQuery sortable() plugin but want to enhance it with a sort indicator. This would be a vertical bar in between the items where the draggable can be dropped. See the image below for an example. Can this easily be achieved with the sortable() plugin? ...

Algorithm to establish ordering amongst a set of items

I have a set of students (referred to as items in the title for generality). Amongst these students, some have a reputation for being rambunctious. We are told about a set of hate relationships of the form 'i hates j'. 'i hates j' does not imply 'j hates i'. We are supposed to arrange the students in rows (front most row numbered 1) in a...

ASP.Net GridView Sorting

I have a grid view with AllowSorting set to true. I get an event onsorting when a sortable header is clicked on. the handler has a parameter "GridViewSortEventArgs e" which has a SortDirection property on it. regardless of how many times you click on the same heading, the SortDirection is always Ascending. I think I'm missing something, ...

Sort a List<T> using query expressions - LINQ C#

I have a problem using Linq to order a structure like this : public class Person { public int ID { get; set; } public List<PersonAttribute> Attributes { get; set; } } public class PersonAttribute { public int ID { get; set; } public string Name { get; set; } public string Value { get; set; } } A person might go li...

Using array_multisort on the same array multiple times?

I have a largish table of data pulled from my database (~1500 rows, each with 10-15 fields) and I'm doing a number of filters and generating some stats and storing these in an excel spreadsheet for the user to download. Rather than hit the database with the same fairly-complicated query over and over with only minor modifications (to th...

What is the best way to efficiently extract a small random subset of a large enumeration?

What is the best way to grab n items from an IEnumerable<T> in random order? I'm writing a store API and need to provide a small set of random items from a sometimes huge enumeration of items. The underlying enumerable is sometimes an array, and sometimes a lazy evaluated filter of said array. Since I'm just grabbing a proportionally ...

changing sorting criteria after the first result

I am selecting from a database of news articles, and I'd prefer to do it all in one query if possible. In the results, I need a sorting criteria that applies ONLY to the first result. In my case, the first result must have an image, but the others should be sorted without caring about their image status. Is this something I can do with...

MbUnit: Testing custom ordered collection

I have a custom collection type of data. This data is sorted by three properties in their order, e.g. take the following example: class Data { public int PropertyA() { get; set; } public int PropertyB() { get; set; } public int PropertyC() { get; set; } } The collection must maintain the order of A, B, C, e.g.: [A, B, C] [1, 2,...

Table operation .net library

In some webpages that I have, I must join some datatables in memory and then use the result as a datasource for a gridview. This in-memory join is the only solution, and I have written a method that takes care of it. I was wondering if there is any library out there that can do such things and other table operations, like ordering and...

sorting and paging with gridview asp.net

I'm trying to get a gridview to sort and page manually with no success. The problem is that when a user clicks the column they want to sort, it sorts that page, but doesn't sort the datasource (dataview) behind the gridview. So when they progress to a different page, their sort is lost. Pretty much I'm looking for a sort that will act...

Which STL container is best for std::sort? (Does it even matter?)

The title speaks for itself .... Does choice of container affects the speed of the default std::sort algorithm somehow or not? For example, if I use list, does the sorting algorithm just switch the node pointers or does it switch the whole data in the nodes? ...

ASP.NET MVC. Clean way to implement persistant sorting?

I still haven`t found any example of sorting implementation through paging in ASP.NET MVC (sort by name->press page 2->page 2 is still sorted by name). I could "hack" it, make it dirty, but i`m sure there have to be good "how-to" guides for this. What about sorting by two columns? ...

Code to create Sorting for a GridView in ASP.net in Code Behind?

Hi This is my code code for the Page_Load Event OdbcConnection myConnection; DataSet dataSet = new DataSet(); OdbcDataAdapter adapter; //making my connection myConnection = new OdbcConnection(ConfigurationManager.ConnectionStrings ["ODBC_ConnectionString"].ConnectionString);...

Compare Function and Multithreading

Assume a multi-threaded environment and a (properly synchronized) class that has one particular procedure procedure SortKeyList (KeyList : TList <Integer>; Inverted : Boolean); that takes a list of keys and sorts it. The procedure uses the RTL quicksort implementation TList.Sort: KeyList.Sort (TComparer <Integer>.Construct (CompareKe...

Stable sort of 2 valued array?

I have an array of objects. the objects have a Boolean value in them that I want to use as a key for sorting the array (all objects with true come before all objects with false) but otherwise leave things in the same order. Is there a simple, in-place, O(n) solution to this? Maybe some variant of radix-sort? ...

Sort List Alphabetically

Hi, I've a List<String> object that contains country names. How can I sort this list alphabetically? Thanks. ...

Sorting Powershell Version

In PowerShell if i have a list of strings containing versions "3.0.1.1","3.2.1.1" etc how can I Sort it the way System.Version would sort it in c# ...