Answered by:
'ddEventType' has a SelectedValue which is invalid because it does not exist in the list of items.

Question
-
User1018471933 posted
If my Dropdown List is connected to a SQL Datasource and i KNOW that there will be result set, then why the heck am I getting this error?
Error: Sys.WebForms.PageRequestManagerServerErrorException: 'ddEventType' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: valueTuesday, December 20, 2011 8:36 AM
Answers
-
User-1360095595 posted
One approach might be to change your SQL select to return say -1 if the value is null. You can use ISNULL for this. And in this case you add a generic item to your DDL with a value of -1 and a text of "Select". Alternatively, handle the formview databound event and in there check if the value is null and change the selectedvalue to the generic item. I think that will work also. You could also add the check inline, that is in the HTML markup itself.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 21, 2011 1:18 PM
All replies
-
User-1360095595 posted
Your code is trying to set the DDL to a value that doesn't exist. Check what you're trying to set the DDL to and check what listitems/options are in the DDL in question.Tuesday, December 20, 2011 8:46 AM -
User-419562455 posted
please show your dropdownlist properties and sqldatasource.
Tuesday, December 20, 2011 8:47 AM -
User-419562455 posted
i hope you bind diffrent datafield in ddl valuefield.
Tuesday, December 20, 2011 8:48 AM -
User1018471933 posted
I keep getting this error now ALL over my Web App. I am not trying to set the DDL value yet, as I am simply trying to get into the Edit/Insert mode of the FormView now (where this DDL is located). It DOES have a result set (what will I do when it doesn't??) and I have even put in a Item Value to try and curb this error, but alas no luck...
Unless, of course, I'm being stupid here thinking that I can put a DDL into a FormView template while very likely this cannot/should not be done??
Here is the ASPX Code for this control (this portion specifically from the Edit template of this FormView):
<td width="300"> <asp:DropDownList ID="ddAccTypes1" runat="server" DataSourceID="sqlGetAccTypes1" DataTextField="TYPE_DESCRIPTION" DataValueField="ACCOUNT_TYPE" SelectedValue='<%# Bind("ACCOUNT_TYPE") %>' Width="200px" AppendDataBoundItems="True"> <asp:ListItem>Select Account Type</asp:ListItem> </asp:DropDownList> <asp:SqlDataSource ID="sqlGetAccTypes1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubManagerRemote %>" SelectCommand="SELECT * FROM [tblACCOUNT_TYPES] ORDER BY [TYPE_DESCRIPTION]"> </asp:SqlDataSource> </td>
Wednesday, December 21, 2011 8:53 AM -
User-1360095595 posted
Yes you are trying to set the value. It's done via the selectedvalue property which you bind to account_type. So the account_type value you're getting, probably from the formview's DataSource, is returning a value which doesn't exists in the DDL based on DataSource you're binding the DDL to.Wednesday, December 21, 2011 8:58 AM -
User1018471933 posted
Hi Metal!
I see. Could this be because the ACCOUNT_TYPE field on the FormView's Datasource actually returns a NULL/empty value?
Wednesday, December 21, 2011 9:07 AM -
User1018471933 posted
I just tested my own question on the Database and it worked. But this spawns another question:
I recently added this new field to the DB Table, which means that it will be NULL to begin with. Is there some code/tecnique I can implement that will overcome this error in future, or should I simply then make sure that a new column, or a column elsewhere that will be bound this way, has data and no NULL values, then?
Wednesday, December 21, 2011 9:11 AM -
User-1360095595 posted
One approach might be to change your SQL select to return say -1 if the value is null. You can use ISNULL for this. And in this case you add a generic item to your DDL with a value of -1 and a text of "Select". Alternatively, handle the formview databound event and in there check if the value is null and change the selectedvalue to the generic item. I think that will work also. You could also add the check inline, that is in the HTML markup itself.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 21, 2011 1:18 PM