Skytide
asked on
dropdownlist has a SelectedValue which is invalid because it does not exist in the list of items
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(Conta iner.DataI tem, "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(Con tainer.Dat aItem, "BirthDate")), 4)
it works!
Any idea why this is happening. I'd prefer to use the "Year" instead of "Right"
Thanks.
Year(DataBinder.Eval(Conta
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(Con
it works!
Any idea why this is happening. I'd prefer to use the "Year" instead of "Right"
Thanks.
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
Convert the year,month,day to integer
u can try like this
CInt(Year(DataBinder.Eval(
or use
CType(Year(DataBinder.Eval
regards
Pradeep
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
ASKER
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.
ASKER
</asp:DropDownList> <
<asp:ListItem Value="1979">1979</asp:Lis
<asp:ListItem Value="1980">1980</asp:Lis
<asp:ListItem Value="1981">1981</asp:Lis
<asp:ListItem Value="1982">1982</asp:Lis
<asp:ListItem></asp:ListIt
BUT when I remove the last blank list item (see below), it gives me the same error.
</asp:DropDownList> <
<asp:ListItem Value="1979">1979</asp:Lis
<asp:ListItem Value="1980">1980</asp:Lis
<asp:ListItem Value="1981">1981</asp:Lis
<asp:ListItem Value="1982">1982</asp:Lis
This really doesn't make any sense to me.