CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.web_forms Tags:
Item Type: NewsGroup Date Entered: 3/31/2008 8:09:39 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 6 Views: 4 Favorited: 0 Favorite
7 Items, 1 Pages 1 |< << Go >> >|
atconway
Asp.Net User
What event can I catch this exception: 'ddlNames' has a SelectedValue which is invalid because it does not exist in the list of items.3/31/2008 8:09:39 PM

0

Which event can I catch the following exception from an ASP.NET Drop Down List?

'ddlNames' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

[ArgumentOutOfRangeException: 'ddlNames' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value]

I understand exactly why this is being thrown; I have an ID I am trying to select in the list that does not exist in the list.  I also have code to check for this upon setting the value and preventing the exception.

However, I still would like to handle this exception more gracefully in the future, just in case I do not have the code in place to handle this condition.  To this point I have not been able to find where to 'Catch' this exception.  Can anyone point me to where this could be trapped?

 


Thank you,

BryianTan
Asp.Net User
Re: What event can I catch this exception: 'ddlNames' has a SelectedValue which is invalid because it does not exist in the list of items.3/31/2008 8:29:20 PM

0

can you show us some code? 


Bryian Tan
MCP
fimine
Asp.Net User
Re: What event can I catch this exception: 'ddlNames' has a SelectedValue which is invalid because it does not exist in the list of items.3/31/2008 8:36:39 PM

0

 You catch it at the poing where your ddlNames.SelectedValue =  is being called.



_____________
Don't forget to mark this post as "Answer" if it indeed answered.
atconway
Asp.Net User
Re: What event can I catch this exception: 'ddlNames' has a SelectedValue which is invalid because it does not exist in the list of items.3/31/2008 8:53:08 PM

0

Actually, it does not throw an exception at that point (I debugged and it goes right on through)

Me.ddlNames.SelectedValue = NamesObject.NameID

The above line of code will not throw any exceptions.  It happens after that code... somewhere.


Thank you,

komakula
Asp.Net User
Re: What event can I catch this exception: 'ddlNames' has a SelectedValue which is invalid because it does not exist in the list of items.3/31/2008 8:58:53 PM

0

write your code in below if condition and try

if ddlnames.selectedvalue>=0 then

end if

atconway
Asp.Net User
Re: What event can I catch this exception: 'ddlNames' has a SelectedValue which is invalid because it does not exist in the list of items.3/31/2008 9:27:46 PM

0

I have code to prevent the exception already as follows:

Dim itemFound As ListItem = ddlNames.Items.FindByValue(NamesObject.NameID)

If (IsNothing(itemFound)) Then

Me.ddlNames.SelectedIndex = 0

Else

Me.ddlNames.SelectedValue = NamesObject.NameID

End If

This is not the issue as I expalined in mt original post.  I am trying to determine what event will capture the exception iof for some reason I did not have the code above.  Does anyone know the event where this is thrown to?  It is NOT thrown immedeatly if I only have this line of code:

Me.ddlNames.SelectedValue = NamesObject.NameID


Thank you,

atconway
Asp.Net User
Re: What event can I catch this exception: 'ddlNames' has a SelectedValue which is invalid because it does not exist in the list of items.4/2/2008 3:16:43 PM

0

I never found the exact event to catch the exception (unfortunantly); I just placed the code from my previous post in the '_DataBound' event and it works.


Thank you,

7 Items, 1 Pages 1 |< << Go >> >|


Free Download:







how to use a sortedlist in a session or cache?

clearing viewstate

adding an event to a textbox in page load

any body know any http link that send sms from asp.net(vb)

how do you disable multiple controls on events

textareas

problem in editing a page

page watermark

how to call c#.net function in one usercontrol from another user control

../ or ~/

autopost back event

caching a dataset, then changing cached dataset on update

lost sessions when passed to c# application form that uses axshdocvw.axwebbrowser

dynamically adding controls

asp:table...every other row different color?

can i have two forms in one .aspx

how to assign class object to an array of class object thru for each loop

desperately need help!!!

unable to get callback for selectedindexchanged on dropdownlist

range validator control breaks after installing vs 2008 beta 2

cursor placement in textbox

urleditor not working for a user control

how to link multiple web forms together?

server.transfer

substitution for 'public sub new'

embedded text files in asp.net 2.0

showing errors in ie7

call the method which is implemented in a user control

creating controls with events at runtime.

interaction between 'web user controls'/pagelets

   
  Privacy | Contact Us
All Times Are GMT