473,320 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How can sort the item in dropdownlist box?

JL
I am used a hashtable for dropdownlist data source but it seems un-sorted on
output.

Anybody who know the sort method in dropdownlist box? thanks a lot
Nov 18 '05 #1
4 3955
ArrayList al=new ArrayList(thedict);
al.Sort(new YourComparer());
ddl.DataSource=al;
ddl.DataTextField="Value";
ddl.DataValueField="Key";
public class YourComparer : IComparer
{
public int Comparer(object x,object y)
{
DictionaryEntry a=(DictionaryEntry)x;
DictionaryEntry b=(DictionaryEntry)y;
return a.Key.ToString().CompareTo(b.Key.ToString());
}
}

--
http://www.lostinet.com/
Lostinet.Web Controls&Components
ComboBox,ComboCalendar DatePicker,SafePwdBox,SmartIFrame,
AlertElement,ConfirmElement,PromptElement,DialogEl ement,ControlHelper
-----------------------

"JL" <jo********@mail.hotmail.com> дÈëÓʼþ
news:%2***************@TK2MSFTNGP11.phx.gbl...
I am used a hashtable for dropdownlist data source but it seems un-sorted on output.

Anybody who know the sort method in dropdownlist box? thanks a lot

Nov 18 '05 #2
Hi,

one way could be adding items (using custom class if you need key & value)
into ArrayList and then sort the ArrayList (probably needs custom comparer
class) and then bind this ArrayList to the DDL.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"JL" <jo********@mail.hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
I am used a hashtable for dropdownlist data source but it seems un-sorted on output.

Anybody who know the sort method in dropdownlist box? thanks a lot

Nov 18 '05 #3
JL
thanks a lot
"Teemu Keiski" <jo****@aspalliance.com> ¦b¶l¥ó
news:OA**************@TK2MSFTNGP10.phx.gbl ¤¤¼¶¼g...
Hi,

one way could be adding items (using custom class if you need key & value)
into ArrayList and then sort the ArrayList (probably needs custom comparer
class) and then bind this ArrayList to the DDL.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"JL" <jo********@mail.hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
I am used a hashtable for dropdownlist data source but it seems
un-sorted on
output.

Anybody who know the sort method in dropdownlist box? thanks a lot


Nov 18 '05 #4
JL
thanks a lot
"Lostinet.Web Support" <lo*********@hotmail.com> ¦b¶l¥ó
news:Op**************@tk2msftngp13.phx.gbl ¤¤¼¶¼g...
ArrayList al=new ArrayList(thedict);
al.Sort(new YourComparer());
ddl.DataSource=al;
ddl.DataTextField="Value";
ddl.DataValueField="Key";
public class YourComparer : IComparer
{
public int Comparer(object x,object y)
{
DictionaryEntry a=(DictionaryEntry)x;
DictionaryEntry b=(DictionaryEntry)y;
return a.Key.ToString().CompareTo(b.Key.ToString());
}
}

--
http://www.lostinet.com/
Lostinet.Web Controls&Components
ComboBox,ComboCalendar DatePicker,SafePwdBox,SmartIFrame,
AlertElement,ConfirmElement,PromptElement,DialogEl ement,ControlHelper
-----------------------

"JL" <jo********@mail.hotmail.com> дÈëÓʼþ
news:%2***************@TK2MSFTNGP11.phx.gbl...
I am used a hashtable for dropdownlist data source but it seems
un-sorted on
output.

Anybody who know the sort method in dropdownlist box? thanks a lot


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: localhost | last post by:
A DataGrid with shows a label in one of the columns when in view mode. When in edit mode, I want to show a dropdown, and have the default selection set to what the textbox used to be. Right now...
3
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
3
by: Sam C | last post by:
Hi, I have an ASP.Net page which has a DropDownList on it. The DDL is populated via a method which is called from the Page_Load if IsPostBack = False. When the form is submitted the...
1
by: g | last post by:
I have a user control that contains a dropdownlist. Using a public property, I can get the selected item. However, I am unsure of how to use that same public property to set the selected item. ...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
3
by: Iain | last post by:
Hi All I have 2 DropDownList boxes on a page. The first (id= "Operation") is populated on PageLoad with the contents of a database table. The second id="WorkStations" will not be populated...
4
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
3
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.