• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 472
  • Last Modified:

SortedList order...

Using a SortedList to diplay the Months in a Dropdown List:

colMonth = New SortedList()
colMonth.Add( "1", "January" )
colMonth.Add( "2", "February" )
colMonth.Add( "3", "March" )
colMonth.Add( "4", "April" )
colMonth.Add( "5", "May" )
colMonth.Add( "6", "June" )
colMonth.Add( "7", "July" )
colMonth.Add( "8", "August" )
colMonth.Add( "9", "September" )
colMonth.Add( "10", "October" )
colMonth.Add( "11", "November" )
colMonth.Add( "12", "December" )

However, when the Dropdown list is displayed it goes in the order of:
      <option value="1">January</option>
      <option value="10">October</option>
      <option value="11">November</option>
      <option value="12">December</option>
      <option value="2">February</option>
      <option value="3">March</option>
      <option selected="selected" value="4">April</option>
      <option value="5">May</option>
      <option value="6">June</option>
      <option value="7">July</option>
      <option value="8">August</option>
      <option value="9">September</option>

Is there anyway of sorting this the right way?
0
gilkesy
Asked:
gilkesy
  • 2
  • 2
2 Solutions
 
NauticalNonsenseCommented:
Are you able to put in 01, 02, 03, 04..... ??

If you're taking that value and doing a Convert.ToInt32 on the backend, should work fine.

0
 
gilkesyAuthor Commented:
I could put in 01, 02, 03.

But I was using this routine to select the current date:

            Dim intMonth As Integer = Convert.ToString(month(now))
            
            for i = 1 to 12
            if intMonth = i then
                  dropStartMonth.SelectedValue = i
            end if
            next

This doesnt work if I use 01, 02, 03
0
 
NauticalNonsenseCommented:
how about something like

dropStartMonth.SelectedItem = Month(i)

??

I totally know what you're saying with the sortedlist, but I haven't found it to be all that flexible.
0
 
gilkesyAuthor Commented:
Dim intMonth As Integer = Convert.ToString(month(now))

for i = 1 to 12
if intMonth = i then
      dropStartMonth.SelectedItem = Month(i)
end if
next


Results in:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30311: Value of type 'Integer' cannot be converted to 'Date'.

Source Error:

 

Line 60:             for i = 1 to 12
Line 61:             if intMonth = i then
Line 62:                   dropStartMonth.SelectedItem = Month(i)
Line 63:             end if
Line 64:             next
 
0
 
trevorhartmanCommented:
can the key object in the Add method be an int instead of a string?

colMonth = New SortedList()
colMonth.Add( 1, "January" )
colMonth.Add( 2, "February" )
colMonth.Add( 3, "March" )
colMonth.Add( 4, "April" )
.
.
.
.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now