CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 2/20/2004 5:31:41 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 3 Views: 65 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
4 Items, 1 Pages 1 |< << Go >> >|
kakashi0124
Asp.Net User
sorting values in Hashtable or sortedList2/20/2004 5:31:41 AM

0/0

hey guys
i need to sort the hashtable or sortedList by the Value, NOT the KEYs
does any one know how to do that?

first my idea was to do
1. select * from table order by value
2. retrieve the data into the Hashtable or sortedList

both of them changes the order of way i insert the data, does anyone know how to do it?? right now i'm trying to over write the compare method and this is my code below



<%@ Page Language="c#" Debug="true" %>
<%@ import Namespace="System.Collections" %>
<%@ import Namespace="System.Globalization" %>
<script runat="server">

private static IHashCodeProvider hashCodeProvider;
private static IComparer comparer;

private static IHashCodeProvider HashCodeProvider {
get {
if (hashCodeProvider == null) {
hashCodeProvider = new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture);
}
return hashCodeProvider;
}
}

private static IComparer Comparer {
get {
if (comparer == null) {
comparer = new SymbolEqualComparer();
}
return comparer;
}
}


private class SymbolEqualComparer: IComparer
{
int IComparer.Compare(object keyLeft, object keyRight)
{
return 1;
}
}


void Page_Load()
{
// Hashtable ht = new Hashtable(null, comparer);
SortedList ht = new SortedList(comparer);

ht.Add("a", "first");
ht.Add("c", "a c");
ht.Add("b", "zzz");
ht.Add("aaa", "an apple");


ht.Add("z", "z");
ht.Add("x", "x");
ht.Add("v", "v");
ht.Add("r", "r");

ArrayList keys = new ArrayList(ht.Keys);
ArrayList Values = new ArrayList(ht.Values);

for(int i = 0; i < keys.Count; i++)
{
Response.Write(keys[i].ToString() + "---->" + Values[i].ToString());
Response.Write("<br>");
}
Response.Write("<br><br><br>");


listSelect.DataSource = ht;
listSelect.DataValueField = "Key";
listSelect.DataTextField = "Value";
listSelect.DataBind();


}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:ListBox id="listSelect" runat="server"></asp:ListBox>
</form>
</body>
</html>
master4eva
Asp.Net User
Re: sorting values in Hashtable or sortedList2/20/2004 1:58:04 PM

0/0

Personally, I would go for the:

select * from table order by value
-- Justin Lovell
kakashi0124
Asp.Net User
Re: sorting values in Hashtable or sortedList2/22/2004 9:31:47 PM

0/0

but that does not work,
everytime when i insert into a hashtable or sort table, they will re-range order of the records, that's why i need to overwrite the comparer method, but it does not seems to be working by the way i'm doing. hmmm does anyone know how?
michaeldfalcone
Asp.Net User
Re: sorting values in Hashtable or sortedList2/23/2004 2:56:37 PM

0/0

Is this of any use:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp01212002.asp

Michael
4 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Pro Visual C++/CLI and the .NET 2.0 Platform Authors: Stephen R. G. Fraser, Pages: 917, Published: 2005
Professional ASP.NET 2.0 Authors: Bill Evjen, Scott Hanselman, Farhan Muhammad, Srinivasa Sivakumar, Devin Rader, Pages: 1253, Published: 2005
Visual Basic.Net by Example Authors: Gabriel Oancea, Robert P. Donald, Pages: 976, Published: 2002
Beginning ASP.NET 1.1 with VB.NET 2003 Authors: Chris Ullman, John Kauffman, Chris Hart, David Sussman, Pages: 888, Published: 2003
Beginning ASP.NET 1.0 with Visual Basic.NET: With Visual Basic .NET Authors: Chris Goode, John Kauffman, Rob Birdwell, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Ollie Cornes, Dave Sussman, Matt Butler, Gary Johnson, Chris Ullman, Ajoy Krishnamoorthy, Juan T. Llibre, Pages: 816, Published: 2002
Beginning ASP.NET 1.1 with Visual C# .NET 2003 Authors: Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry, Pages: 888, Published: 2004
C# Design Patterns: A Tutorial Authors: James William Cooper, Pages: 392, Published: 2002
Visual Basic 2005 with .NET 3.0 Programmer's Reference: Programmer's Reference Authors: Rod Stephens, Pages: 1200, Published: 2007
VB.NET Core Classes in a Nutshell: A Desktop Quick Reference Authors: Budi Kurniawan, Ted Neward, Pages: 558, Published: 2002
Guide to C# and Object Orientation Authors: John Hunt, Pages: 476, Published: 2002

Web:
ASP.NET, SortedList Object and sort order in DropDownList Controls The value can be null. Private Sub PrepareSortedList() Dim slSortedList = New SortedList slSortedList.Add(3, "DataSet") slSortedList.Add(2, "HashTable") ...
Imran's Knowledge Base World: How to sort Hashtable To sort Hashtable best practice is to use SortedList. You can either replace Hashtable ... I override ToString method to see the the value of added object. ...
Diferences between Hashtable and SortedList - DotNetDevelopment ... on a Hashtable object because of the sorting. However, the SortedList offers more flexibility by allowing access to the values either ...
Which collection object to use similar to SortedList\Hashtable - bytes Feb 18, 2006 ... I need to sort this data at one place, so I use sortedlist here. ... I add a few rows(two cols: ID, value) in to new hashtable. ...
The SortedList Collection :: BlackWasp Software Development As with a Hashtable, this pairing of key and value can be accessed as a ... code creates a SortedList that performs case-insensitive sorting of the keys. ...
SortedList Class Operations on a SortedList tend to be slower than operations on a Hashtable because of the sorting. However, the SortedList offers more flexibility by ...
InformIT: .NET Reference Guide > SortedList Jan 1, 2004 ... Like Hashtable, SortedList is based on the IDictionary interface, so every element is a key-and-value pair and can be accessed by the key. ...
A way to sort hashtable - ASP.NET Forums SortedList tmpKatyLinks = new SortedList(); keys.Sort(); ... 'Hashpair class, represents a key-value pair in a hashtable ...
how ti sort hashtable by Value - bytes Feb 12, 2006 ... How can I sort the hashtable wrt the VALUE and not the. ... sorted list, sort the Hashtable into the array only if the "dirty" flag ...
Microsoft Howto QuickStart Tutorial You cannot rely on how a Hashtable will sort its elements ... Remember that the Hashtable and the SortedList both need key-value combinations, ...




Search This Site:










menu navigation

installation error

create dropdownlist dynamicaly also databound..

site log

getting the value of a drop down list in a click event

app_offline.htm file problem

re: query about solution

first time use of masterpages

trouble with background colors...

kodhedz form generator help

securing views

treenode javascript programmability

dotnetnuke.com registration

speed up a website that use a certificate

sql connection method why whynot?

changing the location of the webctrl_client folder

popup calendar date format

authentication works but not if i redirect to a directory?

how to use .net dll in vc++ 6.0 ?

moblog capabilities - mobile phone pictures

getting started without vs.net

file count

some code is not working...

how can i pass selected text of a listbox in querystring......code included

treeview webpart

deriving from treenode

adding an image dynamically to a zone

trying to understand security management in asp.net

my first module - displaying ms reporting services in dnn

buttons and postbackurl

 
All Times Are GMT