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 > general_asp.net.web_parts_and_personalization Tags:
Item Type: NewsGroup Date Entered: 3/18/2008 4:34:29 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 3 Views: 16 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
4 Items, 1 Pages 1 |< << Go >> >|
frostfang
Asp.Net User
Sorted List exception3/18/2008 4:34:29 AM

0/0

I can't figure this out. Sometimes it throws the exception sometimes it works. Right here is the situation, i have a custom property editorpart that i wrote, it edits a custom webpart i worte.

The editor part gets a list of images from a directory then displays them in a drop down list, it then gets a property from the webpart and depending on what is asked will get or set the image in that web part based on the value in the ddlist item (as you'd expect). There is also a file upload that uploads an image to the directory the ddlist gets it's items from. This works fine and has been working great, until i decided to sort the items in the list.

i worte a method that is to sort the items in the list and when i call it sometimes it works but other times it will throw an exception:

Item has already been added. Key in dictionary: 'image.jpg' Key being added: 'image.jpg'

i tried debugging and when it does throw the exception it is going around in the loop again and tries to add it to the SortedList again, here is my code.

 

 Private Sub SortDropDownList(ByVal dd As DropDownList)
        'This might cause issues.

        If Not (dd Is Nothing) Then
            Dim sl As New SortedList

            Dim selected As String = dd.SelectedValue
            For Each i As ListItem In dd.Items
                sl.Add(i.Text, i)
            Next

            dd.Items.Clear()

            Dim o As DictionaryEntry 
            For Each o In sl
                dd.Items.Add(o.Value)
            Next

            dd.SelectedValue = selected
            sl.Clear()
        End If
 End Sub
 Any ideas?

Micky B
Intranet Developer
Som Nath Shukla
Asp.Net User
Re: Sorted List exception3/18/2008 7:36:21 AM

0/0

there are duplicate data in ur DropDownList . to avoid this u can use.

For Each i As ListItem In dd.Items
          if not (sl.contain(i.text) then

      sl.Add(i.Text, i)

 

before adding value check that it already exits or not

 


Thanks and Regards
Som Nath
Please click ?Mark as Answer? on the post if it helps you,
frostfang
Asp.Net User
Re: Sorted List exception3/18/2008 10:37:23 PM

0/0

Thanks for the answer, i knew this would fix the problem, i was really hoping that someone could tell me why this would happen. I call the method inside the overridden RenderContents(...) method of my Custom Editor class, is there something that happens at that point that might mess with my code?


Micky B
Intranet Developer
Som Nath Shukla
Asp.Net User
Re: Sorted List exception3/19/2008 4:28:18 AM

0/0

no there is no problem in ur code it is the property of the sortlist u can not put the duplicate values(keys).


Thanks and Regards
Som Nath
Please click ?Mark as Answer? on the post if it helps you,
4 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Visual Basic.NET Unleashed Authors: Paul Kimmel, Pages: 784, Published: 2002
C# 3.0 Cookbook Authors: Jay Hilyard, Stephen Teilhet, Pages: 886, Published: 2007
Data Structures and Abstractions with Java Authors: Frank M. Carrano, Walter Savitch, Pages: 998, Published: 2006
Java in a Nutshell Authors: David Flanagan, Pages: 1254, Published: 2005
Data Structures with Abstract Data Types and Ada Authors: Daniel F. Stubbs, Neil W. Webre, Pages: 544, Published: 1993
C++ Plus Data Structures Authors: Nell B. Dale, Pages: 781, Published: 2007
Data Abstraction and Problem Solving with Java: Walls and Mirrors Authors: Frank M. Carrano, Janet J. Prichard, Pages: 806, Published: 2000
Mastering Visual Basic.NET Authors: Evangelos Petroutsos, Pages: 1153, Published: 2002
Object-Oriented Data Structures Using Java: data structures usign Java Authors: Nell B. Dale, Daniel T. Joyce, Chip Weems, Pages: 825, Published: 2002
Beginning Algorithms Authors: Simon Harris, James Ross, Pages: 564, Published: 2006

Web:
Sorted List exception - ASP.NET Forums i tried debugging and when it does throw the exception it is going around in the loop again and tries to add it to the SortedList again, here is my code. ...
WHY SORTEDLIST IS USELESS | Dev102.com The exception is occuring because you have two identical integers as keys. From the MSDN article you linked:. “Every key in a SortedList<(Of )>) must be ...
SortedList(TKey, TValue).Add Method (System.Collections.Generic) Adds an element with the specified key and value into the SortedList`2. ... The Add method throws an exception if the new key is ' already in the list. ...
Changing model in a table -> Exception if sorted.: msg#00086 When I receive the new set of data, I do the following: sortedList = new ... http://www.nabble.com/Changing-model-in-a-table--%3E-Exception-if-sorted. ...
.NET csharp SortedList or Dictionary of KEYS ONLY Unlike IDictionary<>> the indexer will not throw an exception on an .... By inheriting from a SortedList of Key, Boolean or a Dictionary of ...
Assignment 2 – Processing a Sorted List of Simple Objects Out ... Inserts item into its proper sorted position in a sorted list. // Throws an exception if the item cannot be placed on the list (list full). ...
SortedList - Try Catch Not working - ASP.NET Forums When I execute it, it doesnt catch the exception like it should. The Key is already part of the OpenWith SortedList so it should throw me an error correct? ...
Re: Changing model in a table -> Exception if sort: msg#00003 The stack trace seems to indicate that the *old* SortedList is still be .... http://www.nabble.com/Changing-model-in-a-table--%3E-Exception-if-sorted. ...
SortedList.Remove Method (System.Collections) If the SortedList object does not contain an element with the specified key, the SortedList remains unchanged. No exception is thrown. ...
Coding Horror: Creating Even More Exceptional Exceptions This console app produces the following (mostly) sorted list of 141 classes in the framework that end in Exception. Now there's really no reason to throw ...

Videos:
Randy Pausch - Time Management Randy Pausch's Time Management talk with English and German subtitles by Friederike Sophie Brand (To activate the subtitles or change the language,...
Lec 1 | MIT 3.091 Introduction to Solid State Chemistry Vision Statement, Administrative Details Introduction Taxonomy of Chemical Species Origins of Modern Chemistry View the complete course at: http:...
The End Of The World prophecy. Les prophéties de la fin des temps. Hidabroot The world is changing. It is coming to an end as we know it. Captivating video about the end of days. Armageddon Gog u Magog Gog-u-Magog end of days ...
Hidabroot Astrologia אסטרולוגיה לפי האסטרולוגיה ולפי מחקרי הגנום האנושי לאחרונה, העתיד נקבע מראש. מהי השקפת היהדות בנושא חשוב זה? האם בידינו להשפיע על עתיד גורלנו? האם בידינו לשנות ...
Santa Monica Council Meeting Santa Monica Council Meeting




Search This Site:










randomly kicked to login page

3.0.12 error on site settings page

saving state information between server requests

dnn 4 modules

great idea

dnn update notifications

navigation with an access site-map provider

vb .net frames

ldap authentication

dnn "adult" website

mind-bending problem with class library function

installed/setup dnn * getting blank browser page

looking for dynamic button control...or so.

tell a friend

best skin designer

owc error, anyone help

administrator disconnected

installation error

treeview set font to bold

master page control code

page access

no ajax project templates in vs2005 on vista

impersonation failure going from 1.0 to 1.1

help with login page

which forum module?

apply theme with vb codefile.

altering variables from sql then displaying

allowdelete?

retrieve current node text from sitemapdatasource?

how to add a new module to dnn 212

 
All Times Are GMT