Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Manipulating Data Prior To Display
Message
De
07/12/2004 10:52:44
 
 
À
07/12/2004 09:35:16
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00967471
Message ID:
00967497
Vues:
13
Kevin,

I've not sorted ArrayLists before, but I have sorted ListViews. The ArrayList.Sort() method needs a parameter that implements the IComparer interface. You'll basically have to implement a Sorter class yourself, but part of your problem with sorting your ArrayList, I think, is that the date is part of the text field (or at least that's what it sounds like from your description), so you'd have to do some string manipulation to get the last part of your text.

To implement a date sorter class, you'd need to do something like this:
public class MyArrayListSorter: IComparer
{
	#region Methods
	public virtual int Compare(object x, object y)
	{
		string s1, s2;

		s1 = x.ToString().Trim();
		s2 = y.ToString().Trim();

		s1 = s1.Substring(s1.Length() - 9);
		s2 = s2.Substring(s2.Length() - 9);

		if (s1.Trim().Length > 0)
			d1 = DateTime.Parse(s1);
		else
			d1 = new DateTime(1900, 1, 1);

		if (s2.Trim().Length > 0)
			d2 = DateTime.Parse(s2);
		else
			d2 = new DateTime(1900, 1, 1);

		if (d1 < d2) {return -1;}
		else if (d1 > d2) {return 1;}
		else {return 0;}
	}
Keep in mind that I haven't actually tested this code ... it's lifted from a ListViewSorter class that I have and tweaked to *maybe* work in your situation. It may need more tweaking. <g>

~~Bonnie


>I am retrieving an ArrayList from a third party .NET web service, and trying to display some of the results on an ASP.NET web page. In fact, I have already managed to get this far.
>
>However, the data is not in the order in which I want it. The data I am extracting contains a text value for each row, the last characters of which are a date in the format dd-mmm-yy. What I want to do is to read out those dates, and sort the list in reverse date order (ie newest first), and then display that list on my web page.
>
>Now, in VFP I could do that in two seconds flat. However, this is c#...
>
>Help please.
>
>TIA, Kevin
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform