Hey guys, this issue has been plaguing me too. In my code, I have a Gridview populated by a database which will have null values in it. The user then has to edit the data in the database until all cells for a row is filled and then, if the data is good,
the user can accept the record into a primary database (which does not allow null values). Optionally, if the data is bad, the user can reject the record and it will be processed again. In order to make things easier for the user, several of the cells will
become drop down lists when the edit button is pressed. I've had trouble getting my update to recognise the value of a DDL so I followed the guide at http://msdn.microsoft.com/en-gb/library/ms972948.aspx in the hopes that I'll get it right this time.
I've only created one DDL for the time being (may as well get one working before I start on all the others) and it will only have the values "Up" or "Down". These are hard coded. Whenever I hit the "edit" button, I get the error:
"'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"
I've tried all the methods here and I can't get anything to work. My code for the particular template field is as follows:
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.</div> <div style="position:
absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">Parameter name: valu</div>
Edit: Almost forgot, if it helps, the data type for the column is 'nvarchar(4)' and nulls are allowed.
UPDATE:
I read something that suggested that if I add a ListItem at the top of the list like below the error would be solved:
And it did! However, as you will all notice (and as I foolishly didn't notice), when I updated, the value of the cell would become 0 or 1 but I want the value to be Up or Down. Changing Value="0" to Value="Up" and 1 to Down yielded the same error as I have
been receiving all this time.
NobleMule
Member
4 Points
9 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Jul 28, 2009 11:50 AM|LINK
Hey guys, this issue has been plaguing me too. In my code, I have a Gridview populated by a database which will have null values in it. The user then has to edit the data in the database until all cells for a row is filled and then, if the data is good, the user can accept the record into a primary database (which does not allow null values). Optionally, if the data is bad, the user can reject the record and it will be processed again. In order to make things easier for the user, several of the cells will become drop down lists when the edit button is pressed. I've had trouble getting my update to recognise the value of a DDL so I followed the guide at http://msdn.microsoft.com/en-gb/library/ms972948.aspx in the hopes that I'll get it right this time.
I've only created one DDL for the time being (may as well get one working before I start on all the others) and it will only have the values "Up" or "Down". These are hard coded. Whenever I hit the "edit" button, I get the error:
"'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"
I've tried all the methods here and I can't get anything to work. My code for the particular template field is as follows:
<asp:TemplateField HeaderText="Direction" SortExpression="Direction"> <EditItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" DataTextField="Direction" SelectedValue='<%# Bind("Direction") %>' AppendDataBoundItems="True"> <asp:ListItem Value="0" Selected="True">Up</asp:ListItem> <asp:ListItem Value="1">Down</asp:ListItem> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label4" runat="server" Text='<%# Bind("Direction") %>'></asp:Label> </ItemTemplate> <ControlStyle BorderColor="#350B59" Width="55px" /> <FooterStyle BorderColor="#350B59" Width="55px" /> <HeaderStyle BorderColor="#350B59" Width="55px" /> <ItemStyle BorderColor="#350B59" Width="55px" /> </asp:TemplateField>Anyone got any ideas? I'm getting desperate!
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">Parameter name: valu</div>Edit: Almost forgot, if it helps, the data type for the column is 'nvarchar(4)' and nulls are allowed.
UPDATE:
I read something that suggested that if I add a ListItem at the top of the list like below the error would be solved:
'<asp:ListItem Value="" Selected="True"></asp:ListItem>'
And it did! However, as you will all notice (and as I foolishly didn't notice), when I updated, the value of the cell would become 0 or 1 but I want the value to be Up or Down. Changing Value="0" to Value="Up" and 1 to Down yielded the same error as I have been receiving all this time.