EDN Admin
Well-known member
Hey guys,
Having a bit of a problem, ive only been programming in C# and ASP.net for 3/4 months but Im getting the hang of it. Just need some help on something which Im sure is minor.
Im trying to put dropdown lists in my gridview but not having success.
The error Im getting is
"ddlDeviceType has a SelectedValue which is invalid because it does not exist in the list of items.<br/>
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.
http://msdn.microsoft.com/en-us/library/ms178294(VS.80).aspx MSDN Tutorial
Heres my code, thanks for any help guys!
ASP Code
<pre class="prettyprint <%@ 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>
<aspropDownList ID="ddlDeviceType" runat="server"
DataSourceID="SqlDataSource2" DataTextField="Description"
DataValueField="Description" SelectedValue=<%# Bind("DeviceType") %>>
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<aspropDownList ID="ddlDeviceType" runat="server"
DataSourceID="SqlDataSource2" DataTextField="Description"
DataValueField="Description" SelectedValue=<%# Bind("DeviceType") %>>
</aspropDownList>
</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>
<asparameter Name="original_ID" Type="Int32" />
<asparameter Name="original_DeviceType" Type="Int32" />
<asparameter Name="original_Manufacturer" Type="Int32" />
<asparameter Name="original_SerialNumber" Type="String" />
<asparameter Name="original_Model" Type="Int32" />
<asparameter Name="original_Warrenty" Type="Int32" />
<asparameter Name="original_CarePack" Type="Int32" />
<asparameter Name="original_AssetTag" Type="Int32" />
<asparameter DbType="Date" Name="original_DateOfPurchase" />
<asparameter Name="original_CostPrice" Type="Decimal" />
<asparameter Name="original_DepreciationType" Type="Int32" />
<asparameter Name="original_DepreciationRate" Type="Int32" />
<asparameter Name="original_TotalDepreciation" Type="Decimal" />
<asparameter Name="original_NetBookValue" Type="Decimal" />
</DeleteParameters>
<InsertParameters>
<asparameter Name="DeviceType" Type="Int32" />
<asparameter Name="Manufacturer" Type="Int32" />
<asparameter Name="SerialNumber" Type="String" />
<asparameter Name="Model" Type="Int32" />
<asparameter Name="Warrenty" Type="Int32" />
<asparameter Name="CarePack" Type="Int32" />
<asparameter Name="AssetTag" Type="Int32" />
<asparameter DbType="Date" Name="DateOfPurchase" />
<asparameter Name="CostPrice" Type="Decimal" />
<asparameter Name="DepreciationType" Type="Int32" />
<asparameter Name="DepreciationRate" Type="Int32" />
<asparameter Name="TotalDepreciation" Type="Decimal" />
<asparameter Name="NetBookValue" Type="Decimal" />
</InsertParameters>
<UpdateParameters>
<asparameter Name="DeviceType" Type="Int32" />
<asparameter Name="Manufacturer" Type="Int32" />
<asparameter Name="SerialNumber" Type="String" />
<asparameter Name="Model" Type="Int32" />
<asparameter Name="Warrenty" Type="Int32" />
<asparameter Name="CarePack" Type="Int32" />
<asparameter Name="AssetTag" Type="Int32" />
<asparameter DbType="Date" Name="DateOfPurchase" />
<asparameter Name="CostPrice" Type="Decimal" />
<asparameter Name="DepreciationType" Type="Int32" />
<asparameter Name="DepreciationRate" Type="Int32" />
<asparameter Name="TotalDepreciation" Type="Decimal" />
<asparameter Name="NetBookValue" Type="Decimal" />
<asparameter Name="original_ID" Type="Int32" />
<asparameter Name="original_DeviceType" Type="Int32" />
<asparameter Name="original_Manufacturer" Type="Int32" />
<asparameter Name="original_SerialNumber" Type="String" />
<asparameter Name="original_Model" Type="Int32" />
<asparameter Name="original_Warrenty" Type="Int32" />
<asparameter Name="original_CarePack" Type="Int32" />
<asparameter Name="original_AssetTag" Type="Int32" />
<asparameter DbType="Date" Name="original_DateOfPurchase" />
<asparameter Name="original_CostPrice" Type="Decimal" />
<asparameter Name="original_DepreciationType" Type="Int32" />
<asparameter Name="original_DepreciationRate" Type="Int32" />
<asparameter Name="original_TotalDepreciation" Type="Decimal" />
<asparameter 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>
[/code]
<br/>
Hope I made sense!
Thanks again. http://msdn.microsoft.com/en-us/library/ms178294(VS.80).aspx
<br/>
View the full article
Having a bit of a problem, ive only been programming in C# and ASP.net for 3/4 months but Im getting the hang of it. Just need some help on something which Im sure is minor.
Im trying to put dropdown lists in my gridview but not having success.
The error Im getting is
"ddlDeviceType has a SelectedValue which is invalid because it does not exist in the list of items.<br/>
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.
http://msdn.microsoft.com/en-us/library/ms178294(VS.80).aspx MSDN Tutorial
Heres my code, thanks for any help guys!
ASP Code
<pre class="prettyprint <%@ 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>
<aspropDownList ID="ddlDeviceType" runat="server"
DataSourceID="SqlDataSource2" DataTextField="Description"
DataValueField="Description" SelectedValue=<%# Bind("DeviceType") %>>
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<aspropDownList ID="ddlDeviceType" runat="server"
DataSourceID="SqlDataSource2" DataTextField="Description"
DataValueField="Description" SelectedValue=<%# Bind("DeviceType") %>>
</aspropDownList>
</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>
<asparameter Name="original_ID" Type="Int32" />
<asparameter Name="original_DeviceType" Type="Int32" />
<asparameter Name="original_Manufacturer" Type="Int32" />
<asparameter Name="original_SerialNumber" Type="String" />
<asparameter Name="original_Model" Type="Int32" />
<asparameter Name="original_Warrenty" Type="Int32" />
<asparameter Name="original_CarePack" Type="Int32" />
<asparameter Name="original_AssetTag" Type="Int32" />
<asparameter DbType="Date" Name="original_DateOfPurchase" />
<asparameter Name="original_CostPrice" Type="Decimal" />
<asparameter Name="original_DepreciationType" Type="Int32" />
<asparameter Name="original_DepreciationRate" Type="Int32" />
<asparameter Name="original_TotalDepreciation" Type="Decimal" />
<asparameter Name="original_NetBookValue" Type="Decimal" />
</DeleteParameters>
<InsertParameters>
<asparameter Name="DeviceType" Type="Int32" />
<asparameter Name="Manufacturer" Type="Int32" />
<asparameter Name="SerialNumber" Type="String" />
<asparameter Name="Model" Type="Int32" />
<asparameter Name="Warrenty" Type="Int32" />
<asparameter Name="CarePack" Type="Int32" />
<asparameter Name="AssetTag" Type="Int32" />
<asparameter DbType="Date" Name="DateOfPurchase" />
<asparameter Name="CostPrice" Type="Decimal" />
<asparameter Name="DepreciationType" Type="Int32" />
<asparameter Name="DepreciationRate" Type="Int32" />
<asparameter Name="TotalDepreciation" Type="Decimal" />
<asparameter Name="NetBookValue" Type="Decimal" />
</InsertParameters>
<UpdateParameters>
<asparameter Name="DeviceType" Type="Int32" />
<asparameter Name="Manufacturer" Type="Int32" />
<asparameter Name="SerialNumber" Type="String" />
<asparameter Name="Model" Type="Int32" />
<asparameter Name="Warrenty" Type="Int32" />
<asparameter Name="CarePack" Type="Int32" />
<asparameter Name="AssetTag" Type="Int32" />
<asparameter DbType="Date" Name="DateOfPurchase" />
<asparameter Name="CostPrice" Type="Decimal" />
<asparameter Name="DepreciationType" Type="Int32" />
<asparameter Name="DepreciationRate" Type="Int32" />
<asparameter Name="TotalDepreciation" Type="Decimal" />
<asparameter Name="NetBookValue" Type="Decimal" />
<asparameter Name="original_ID" Type="Int32" />
<asparameter Name="original_DeviceType" Type="Int32" />
<asparameter Name="original_Manufacturer" Type="Int32" />
<asparameter Name="original_SerialNumber" Type="String" />
<asparameter Name="original_Model" Type="Int32" />
<asparameter Name="original_Warrenty" Type="Int32" />
<asparameter Name="original_CarePack" Type="Int32" />
<asparameter Name="original_AssetTag" Type="Int32" />
<asparameter DbType="Date" Name="original_DateOfPurchase" />
<asparameter Name="original_CostPrice" Type="Decimal" />
<asparameter Name="original_DepreciationType" Type="Int32" />
<asparameter Name="original_DepreciationRate" Type="Int32" />
<asparameter Name="original_TotalDepreciation" Type="Decimal" />
<asparameter 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>
[/code]
<br/>
Hope I made sense!
Thanks again. http://msdn.microsoft.com/en-us/library/ms178294(VS.80).aspx
<br/>
View the full article