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

Question
-
Hey guys,
Having a bit of a problem, i've only been programming in C# and ASP.net for 3/4 months but I'm getting the hang of it. Just need some help on something which I'm sure is minor.
I'm trying to put dropdown lists in my gridview but not having success.
The error I'm getting is
- "'ddlDeviceType' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"
This is getting frustrating ,but hey thats programming. Any help would be great.
I followed this tutorial step by step but now get the error.
Heres my code, thanks for any help guys!
ASP Code
<%@ Page Title = "Show Equipment" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="ShowEquipment.aspx.cs" Inherits="ShowEquipment" %> <%@ Register assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> <style type="text/css"> body { background-image:url('RBKSmall.png'); } .All { height: 268px; width: 918px; } </style> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1"> <Columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" /> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" /> <asp:TemplateField HeaderText="DeviceType" SortExpression="DeviceType"> <EditItemTemplate> <asp:DropDownList ID="ddlDeviceType" runat="server" DataSourceID="SqlDataSource2" DataTextField="Description" DataValueField="Description" SelectedValue='<%# Bind("DeviceType") %>'> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:DropDownList ID="ddlDeviceType" runat="server" DataSourceID="SqlDataSource2" DataTextField="Description" DataValueField="Description" SelectedValue='<%# Bind("DeviceType") %>'> </asp:DropDownList> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" SortExpression="Manufacturer" /> <asp:BoundField DataField="SerialNumber" HeaderText="SerialNumber" SortExpression="SerialNumber" /> <asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" /> <asp:BoundField DataField="Warrenty" HeaderText="Warrenty" SortExpression="Warrenty" /> <asp:BoundField DataField="CarePack" HeaderText="CarePack" SortExpression="CarePack" /> <asp:BoundField DataField="AssetTag" HeaderText="AssetTag" SortExpression="AssetTag" /> <asp:BoundField DataField="DateOfPurchase" HeaderText="DateOfPurchase" SortExpression="DateOfPurchase" /> <asp:BoundField DataField="CostPrice" HeaderText="CostPrice" SortExpression="CostPrice" /> <asp:BoundField DataField="DepreciationType" HeaderText="DepreciationType" SortExpression="DepreciationType" /> <asp:BoundField DataField="DepreciationRate" HeaderText="DepreciationRate" SortExpression="DepreciationRate" /> <asp:BoundField DataField="TotalDepreciation" HeaderText="TotalDepreciation" SortExpression="TotalDepreciation" /> <asp:BoundField DataField="NetBookValue" HeaderText="NetBookValue" SortExpression="NetBookValue" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:MarksDatabaseConnectionString %>" DeleteCommand="DELETE FROM [Equipment] WHERE [ID] = @original_ID AND [DeviceType] = @original_DeviceType AND [Manufacturer] = @original_Manufacturer AND [SerialNumber] = @original_SerialNumber AND [Model] = @original_Model AND [Warrenty] = @original_Warrenty AND (([CarePack] = @original_CarePack) OR ([CarePack] IS NULL AND @original_CarePack IS NULL)) AND (([AssetTag] = @original_AssetTag) OR ([AssetTag] IS NULL AND @original_AssetTag IS NULL)) AND [DateOfPurchase] = @original_DateOfPurchase AND [CostPrice] = @original_CostPrice AND (([DepreciationType] = @original_DepreciationType) OR ([DepreciationType] IS NULL AND @original_DepreciationType IS NULL)) AND (([DepreciationRate] = @original_DepreciationRate) OR ([DepreciationRate] IS NULL AND @original_DepreciationRate IS NULL)) AND (([TotalDepreciation] = @original_TotalDepreciation) OR ([TotalDepreciation] IS NULL AND @original_TotalDepreciation IS NULL)) AND (([NetBookValue] = @original_NetBookValue) OR ([NetBookValue] IS NULL AND @original_NetBookValue IS NULL))" InsertCommand="INSERT INTO [Equipment] ([DeviceType], [Manufacturer], [SerialNumber], [Model], [Warrenty], [CarePack], [AssetTag], [DateOfPurchase], [CostPrice], [DepreciationType], [DepreciationRate], [TotalDepreciation], [NetBookValue]) VALUES (@DeviceType, @Manufacturer, @SerialNumber, @Model, @Warrenty, @CarePack, @AssetTag, @DateOfPurchase, @CostPrice, @DepreciationType, @DepreciationRate, @TotalDepreciation, @NetBookValue)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Equipment]" UpdateCommand="UPDATE [Equipment] SET [DeviceType] = @DeviceType, [Manufacturer] = @Manufacturer, [SerialNumber] = @SerialNumber, [Model] = @Model, [Warrenty] = @Warrenty, [CarePack] = @CarePack, [AssetTag] = @AssetTag, [DateOfPurchase] = @DateOfPurchase, [CostPrice] = @CostPrice, [DepreciationType] = @DepreciationType, [DepreciationRate] = @DepreciationRate, [TotalDepreciation] = @TotalDepreciation, [NetBookValue] = @NetBookValue WHERE [ID] = @original_ID AND [DeviceType] = @original_DeviceType AND [Manufacturer] = @original_Manufacturer AND [SerialNumber] = @original_SerialNumber AND [Model] = @original_Model AND [Warrenty] = @original_Warrenty AND (([CarePack] = @original_CarePack) OR ([CarePack] IS NULL AND @original_CarePack IS NULL)) AND (([AssetTag] = @original_AssetTag) OR ([AssetTag] IS NULL AND @original_AssetTag IS NULL)) AND [DateOfPurchase] = @original_DateOfPurchase AND [CostPrice] = @original_CostPrice AND (([DepreciationType] = @original_DepreciationType) OR ([DepreciationType] IS NULL AND @original_DepreciationType IS NULL)) AND (([DepreciationRate] = @original_DepreciationRate) OR ([DepreciationRate] IS NULL AND @original_DepreciationRate IS NULL)) AND (([TotalDepreciation] = @original_TotalDepreciation) OR ([TotalDepreciation] IS NULL AND @original_TotalDepreciation IS NULL)) AND (([NetBookValue] = @original_NetBookValue) OR ([NetBookValue] IS NULL AND @original_NetBookValue IS NULL))"> <DeleteParameters> <asp:Parameter Name="original_ID" Type="Int32" /> <asp:Parameter Name="original_DeviceType" Type="Int32" /> <asp:Parameter Name="original_Manufacturer" Type="Int32" /> <asp:Parameter Name="original_SerialNumber" Type="String" /> <asp:Parameter Name="original_Model" Type="Int32" /> <asp:Parameter Name="original_Warrenty" Type="Int32" /> <asp:Parameter Name="original_CarePack" Type="Int32" /> <asp:Parameter Name="original_AssetTag" Type="Int32" /> <asp:Parameter DbType="Date" Name="original_DateOfPurchase" /> <asp:Parameter Name="original_CostPrice" Type="Decimal" /> <asp:Parameter Name="original_DepreciationType" Type="Int32" /> <asp:Parameter Name="original_DepreciationRate" Type="Int32" /> <asp:Parameter Name="original_TotalDepreciation" Type="Decimal" /> <asp:Parameter Name="original_NetBookValue" Type="Decimal" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="DeviceType" Type="Int32" /> <asp:Parameter Name="Manufacturer" Type="Int32" /> <asp:Parameter Name="SerialNumber" Type="String" /> <asp:Parameter Name="Model" Type="Int32" /> <asp:Parameter Name="Warrenty" Type="Int32" /> <asp:Parameter Name="CarePack" Type="Int32" /> <asp:Parameter Name="AssetTag" Type="Int32" /> <asp:Parameter DbType="Date" Name="DateOfPurchase" /> <asp:Parameter Name="CostPrice" Type="Decimal" /> <asp:Parameter Name="DepreciationType" Type="Int32" /> <asp:Parameter Name="DepreciationRate" Type="Int32" /> <asp:Parameter Name="TotalDepreciation" Type="Decimal" /> <asp:Parameter Name="NetBookValue" Type="Decimal" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="DeviceType" Type="Int32" /> <asp:Parameter Name="Manufacturer" Type="Int32" /> <asp:Parameter Name="SerialNumber" Type="String" /> <asp:Parameter Name="Model" Type="Int32" /> <asp:Parameter Name="Warrenty" Type="Int32" /> <asp:Parameter Name="CarePack" Type="Int32" /> <asp:Parameter Name="AssetTag" Type="Int32" /> <asp:Parameter DbType="Date" Name="DateOfPurchase" /> <asp:Parameter Name="CostPrice" Type="Decimal" /> <asp:Parameter Name="DepreciationType" Type="Int32" /> <asp:Parameter Name="DepreciationRate" Type="Int32" /> <asp:Parameter Name="TotalDepreciation" Type="Decimal" /> <asp:Parameter Name="NetBookValue" Type="Decimal" /> <asp:Parameter Name="original_ID" Type="Int32" /> <asp:Parameter Name="original_DeviceType" Type="Int32" /> <asp:Parameter Name="original_Manufacturer" Type="Int32" /> <asp:Parameter Name="original_SerialNumber" Type="String" /> <asp:Parameter Name="original_Model" Type="Int32" /> <asp:Parameter Name="original_Warrenty" Type="Int32" /> <asp:Parameter Name="original_CarePack" Type="Int32" /> <asp:Parameter Name="original_AssetTag" Type="Int32" /> <asp:Parameter DbType="Date" Name="original_DateOfPurchase" /> <asp:Parameter Name="original_CostPrice" Type="Decimal" /> <asp:Parameter Name="original_DepreciationType" Type="Int32" /> <asp:Parameter Name="original_DepreciationRate" Type="Int32" /> <asp:Parameter Name="original_TotalDepreciation" Type="Decimal" /> <asp:Parameter Name="original_NetBookValue" Type="Decimal" /> </UpdateParameters> </asp:SqlDataSource> <br /> <br /> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:MarksDatabaseConnectionString %>" SelectCommand="SELECT DISTINCT [Description] FROM [DeviceType]"> </asp:SqlDataSource> <br /> </asp:Content>
Hope I made sense!
- Moved by Mike Dos Zhang Wednesday, June 6, 2012 7:59 AM (From:Visual C# General)
Tuesday, June 5, 2012 1:55 PM - "'ddlDeviceType' has a SelectedValue which is invalid because it does not exist in the list of items.
Answers
-
Thanks guys, will post my stuff over there. Sorry about this!
- Marked as answer by MConnollydev Tuesday, July 10, 2012 8:36 AM
Wednesday, June 6, 2012 8:14 AM
All replies
-
Hi,
You should be looking for asp questions at http://forums.asp.net/.
any how, this could be with scenario, when you try to select item, which is removed or not existed, in dropdown list. better solution try to avoid having SelectedValue from <asp:DropDown and from code-behind search the item and select the value.
I hope this helps you...
If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
- Proposed as answer by Mr. Wharty Wednesday, June 6, 2012 8:27 AM
Tuesday, June 5, 2012 3:24 PM -
Hi MConnollydev,
According to your problem, I think the ASP.NET forum is better for you, because there are more experienced experts on this field. Please try ASP.NET forum: http://forums.asp.net/
Sorry for any inconvenience.
Have a nice day.
Alexander Sun [MSFT]
MSDN Community Support | Feedback to us
Wednesday, June 6, 2012 7:58 AM -
Thanks guys, will post my stuff over there. Sorry about this!
- Marked as answer by MConnollydev Tuesday, July 10, 2012 8:36 AM
Wednesday, June 6, 2012 8:14 AM