Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old August 11th, 2013, 07:10 AM
Registered User
Points: 47, Level: 1
Points: 47, Level: 1 Points: 47, Level: 1 Points: 47, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I am sorry for my jargon. I used term "run" in meaning of debugging. When I debug with "selectedValue" property in my dropdownlist, I get the following error in my browser. But if I delete the "selectedValue" from my dropdownlist, there is no error. But the value wont entering the database. It'll return null in the database.

Code:
Server Error in '/WebSite1' Application.
'ddlStatus' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'ddlStatus' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

I hope my explanation can help u in figuring my error.
Reply With Quote
  #12 (permalink)  
Old August 11th, 2013, 07:31 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
'ddlStatus' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
Aha, but this means something completely different.

This error shows that your code works fine, but that the data you try to preselect in the drop down does not exist.

There could be two reasons for this:

1. The Status column in the database contains a value that is not New, Pending or Complete. This would be the case if it was null.

2. The database is bound dynamically, but you haven't called DataBind yet (and thus its Items collection is still empty). In that case call DataBind() on the drop down before you do other binding.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #13 (permalink)  
Old August 11th, 2013, 07:40 AM
Registered User
Points: 47, Level: 1
Points: 47, Level: 1 Points: 47, Level: 1 Points: 47, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you for your reply :) It does help me understand the error.

But I'm unable to understand point no.2.

Code:
2. The database is bound dynamically, but you haven't called DataBind yet (and thus its Items collection is still empty). In that case call DataBind() on the drop down before you do other binding.
How can I called databind specifically for this dropdownlist?
Reply With Quote
  #14 (permalink)  
Old August 11th, 2013, 07:42 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You may not have to as it's a static list, isn't it? I mean, the items are not coming from a database are they?

My guess is that your data in the database is incorrect. I think you fix it by deleting or updating existing data. Then use a drop-down for the Insert template as well so you can't insert invalid values anymore.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #15 (permalink)  
Old August 11th, 2013, 08:05 AM
Registered User
Points: 47, Level: 1
Points: 47, Level: 1 Points: 47, Level: 1 Points: 47, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
Default

My data is indeed a static list. As you can see in my code, it was previously using a textbox as editing method & binding the data. It works fine if I edit it through textbox. But I was required to use dropdownlist to control the data entered, problems occured. So, I guess my database is fine.

I tried using your tips by insert the same dropdownlist in my insert template, but the same error still come up. The error still comeout as below.

Code:
ddlStatus' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
can you give me an example of code to fix this?
Reply With Quote
  #16 (permalink)  
Old August 11th, 2013, 08:30 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
I tried using your tips by insert the same dropdownlist in my insert template, but the same error still come up.
For the InsertTemplate? Or for Edit? For the Insert you can't use this as there is no selected data to use. For the Edit template, it could mean your data is still incorrect.

Quote:
can you give me an example of code to fix this?
Take a look at the Status column in the database for your existing records. What data does it contain? I am guessing there is a value that does not exist as an item in your drop-down list.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #17 (permalink)  
Old August 11th, 2013, 09:19 AM
Registered User
Points: 47, Level: 1
Points: 47, Level: 1 Points: 47, Level: 1 Points: 47, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
Default

inside my Status column, there is "Null" for the particular status I am editing.

For example, data with ID 1 with Status "New" . But then I want to edit it to "Pending". So I chose "Pending" from my dropdownlist.

Then the formview view nothing in my formview. When I checked the database, it ha "Null" in it.

Do I need coding behind the page, cos I dont have one (since I am not pretty good at coding behind the page)..

And I am using VB with ASP.Net 3.5
Reply With Quote
  #18 (permalink)  
Old August 11th, 2013, 09:22 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Is Null a valid state? If not, I would do this:

1. Manually correct the data in the database.

2. Use a DropDownList in the Insert template so users cannot accidentally insert null anymore.

If it is valid state, you could normalize it to an empty string in the SQL statement (using COALESCE) and then add an item to the drop down list that has a value of an empty string.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #19 (permalink)  
Old August 11th, 2013, 09:38 AM
Registered User
Points: 47, Level: 1
Points: 47, Level: 1 Points: 47, Level: 1 Points: 47, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I really wish I can understand what you said here, but it did not ring the bells.

If I email to you the whole entire website (its just a simple website) including the database, will you help me to look at it. Its in the page called PaparAduan.aspx

Please please please help me.

P/S: May be not the entire website, just the relevant pages & database.

Last edited by jlandan2; August 11th, 2013 at 09:40 AM..
Reply With Quote
  #20 (permalink)  
Old August 11th, 2013, 09:44 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Before we do that, answer one question:

Is Null a valid state for the Status column? That is, do you want to allow Null?

If not, just go to your database, and replace each occurrence of null in something like New in the Status column.

That should fix the problem, shouldn't it?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using dropdown list sophia BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 4 October 31st, 2009 02:46 PM
Dropdown list maha .NET Framework 2.0 7 April 28th, 2007 12:32 AM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
HELP WITH DROPDOWN LIST enavas Excel VBA 1 April 6th, 2004 02:08 PM



All times are GMT -4. The time now is 08:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.