Solved

dropdownlist has a SelectedValue which is invalid because it does not exist in the list of items

Posted on 2006-07-14
5
389 Views
Last Modified: 2008-02-01
I have a dropdownlist ("ddlYear") in a formsview that is populated with years (used for the user's birthdate). I set the selectedvalue to:

Year(DataBinder.Eval(Container.DataItem, "BirthDate"))

I also check that the datetime value I'm grabbing from the database is included in the dropdownlist. However, when I load the page it gives me this error:

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

I bound the item to a text box to see if the year is being grabbed, and it is.

The strange thing is that if I set the selected value to: Right((DataBinder.Eval(Container.DataItem, "BirthDate")), 4)

it works!

Any idea why this is happening. I'd prefer to use the "Year" instead of "Right"

Thanks.
0
Comment
Question by:Skytide
  • 3
  • 2
5 Comments
 

Author Comment

by:Skytide
ID: 17113454
Ok, it gets even weirder. When I have the code below, it works.

</asp:DropDownList>&nbsp;<asp:DropDownList ID="ddlYear" runat="server" SelectedValue='<%# Right((DataBinder.Eval(Container.DataItem, "BirthDate")), 4) %>'>
                <asp:ListItem Value="1979">1979</asp:ListItem>
                <asp:ListItem Value="1980">1980</asp:ListItem>
                <asp:ListItem Value="1981">1981</asp:ListItem>
                <asp:ListItem Value="1982">1982</asp:ListItem>
                <asp:ListItem></asp:ListItem>

BUT when I remove the last blank list item (see below), it gives me the same error.

</asp:DropDownList>&nbsp;<asp:DropDownList ID="ddlYear" runat="server" SelectedValue='<%# Right((DataBinder.Eval(Container.DataItem, "BirthDate")), 4) %>'>
                <asp:ListItem Value="1979">1979</asp:ListItem>
                <asp:ListItem Value="1980">1980</asp:ListItem>
                <asp:ListItem Value="1981">1981</asp:ListItem>
                <asp:ListItem Value="1982">1982</asp:ListItem>

This really doesn't make any sense to me.

0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 17113491
hi,

Convert the year,month,day to integer
u can try like this

CInt(Year(DataBinder.Eval(Container.DataItem, "BirthDate")))
or use
CType(Year(DataBinder.Eval(Container.DataItem, "BirthDate")),integer)

regards
Pradeep

0
 
LVL 7

Accepted Solution

by:
pradeepsudharsan earned 500 total points
ID: 17113524
or
Convert the year,month,day to string
u can try like this

CString(Year(DataBinder.Eval(Container.DataItem, "BirthDate")))
or use
CType(Year(DataBinder.Eval(Container.DataItem, "BirthDate")),String)


or pass  the value to any java script variable and convert it to string
0
 

Author Comment

by:Skytide
ID: 17115222
I still get the same error. Maybe I can set the SelectedValue in the code behind, in the DataBound Event. I'm thinking I can extract the date from a hidden field that is set to (bind("BirthDate")). Is there a way to extract the date from the DataBound event w/o using a hidden field?
0
 

Author Comment

by:Skytide
ID: 17139662
I just ended up using a hidden field, finding the control in the code behind and setting the selected value of my dropdownlist to the hidden field.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now