Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > dropdownlist has a selectedvalue which is invalid because it does not exist in the list of items.

Reply
Thread Tools

dropdownlist has a selectedvalue which is invalid because it does not exist in the list of items.

 
 
Jason
Guest
Posts: n/a
 
      08-07-2007
I'm trying to use a databound dropdown list in a grid view. I can't
seem to get this to work. If I Bind on a text box it works fine.
Otherwise I get the error below

'ddlDisplayArt' has a SelectedValue which is invalid because it does
not exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'ddlDisplayArt'
has a SelectedValue which is invalid because it does not exist in the
list of items.
Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace
below.

Stack Trace:


[ArgumentOutOfRangeException: 'ddlDisplayArt' has a SelectedValue
which is invalid because it does not exist in the list of items.
Parameter name: value]

System.Web.UI.WebControls.ListControl.PerformDataB inding(IEnumerable
dataSource) +1822067
System.Web.UI.WebControls.ListControl.OnDataBindin g(EventArgs e)
+104
System.Web.UI.WebControls.ListControl.PerformSelec t() +31
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +70
System.Web.UI.Control.DataBindChildren() +216
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +216
System.Web.UI.Control.DataBind() +12
System.Web.UI.Control.DataBindChildren() +216
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +216
System.Web.UI.Control.DataBind() +12
System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32
dataSourceIndex, DataControlRowType rowType, DataControlRowState
rowState, Boolean dataBind, Object dataItem, DataControlField[]
fields, TableRowCollection rows, PagedDataSource pagedDataSource) +221
System.Web.UI.WebControls.GridView.CreateChildCont rols(IEnumerable
dataSource, Boolean dataBinding) +3004

System.Web.UI.WebControls.CompositeDataBoundContro l.PerformDataBinding(IEnumerable
data) +59
System.Web.UI.WebControls.GridView.PerformDataBind ing(IEnumerable
data) +11

System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable
data) +111
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments
arguments, DataSourceViewSelectCallback callback) +29
System.Web.UI.WebControls.DataBoundControl.Perform Select() +149
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +70
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound()
+82

System.Web.UI.WebControls.CompositeDataBoundContro l.CreateChildControls()
+69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +41
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1360


Here's the code

<%@ Page Language="C#" MasterPageFile="~/Admin/AdminMasterPage.master"
AutoEventWireup="true" CodeFile="ManageArtists.aspx.cs"
Inherits="Admin_ManageArtists" Title="Turning Point Gallery - Artist
Administration" StylesheetTheme="Admin_Theme" %>
<asp:Content ID="cntMain" ContentPlaceHolderID="cphMain"
Runat="Server">
<asp:ObjectDataSource ID="odsArtists"
TypeName="TurningPointGalleryTableAdapters.ArtistT ableAdapter"
runat="server"
SelectMethod="GetArtists" UpdateMethod="Update" DeleteMethod="Delete"
InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" >
<InsertParameters>
<asparameter Name="FirstName" Type="string" />
<asparameter Name="LastName" Type="string" />
<asparameter Name="DisplayName" Type="string" />
<asparameter Name="Profile" Type="string" />
<asparameter Name="DisplayArtId" Type="int32" />
</InsertParameters>
<UpdateParameters>
<asparameter Name="Original_ArtistId" Type="Int32" />
<asparameter Name="ArtistId" Type="int32" />
<asparameter Name="FirstName" Type="string" />
<asparameter Name="LastName" Type="string" />
<asparameter Name="DisplayName" Type="string" />
<asparameter Name="Profile" Type="string" />
<asparameter Name="DisplayArtId" Type="int32" />
</UpdateParameters>
<DeleteParameters>
<asparameter Name="Original_ArtistId" Type="int32" />
</DeleteParameters>
</asp:ObjectDataSource>

<asp:ObjectDataSource ID="odsAllArtwork"
TypeName="TurningPointGalleryTableAdapters.Artwork TableAdapter"
runat="server" SelectMethod="GetArtwork" />

<asp:ObjectDataSource ID="odsArtwork"
TypeName="TurningPointGalleryTableAdapters.Artwork TableAdapter"
runat="server" SelectMethod="GetArtworkByArtistId"
InsertMethod="Insert" UpdateMethod="Update" DeleteMethod="Delete"
OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:ControlParameter Name="ArtistId" ControlID="grdArtists"
PropertyName="SelectedValue" />
</SelectParameters>
<InsertParameters>
<asparameter Name="ImageURL" Type="string" />
<asparameter Name="Title" Type="string" />
<asparameter Name="Height" Type="int32" />
<asparameter Name="Width" Type="int32" />
<asparameter Name="Depth" Type="int32" />
<asparameter Name="Blurb" Type="string" />
<asparameter Name="ArtistId" Type="int32" />
</InsertParameters>
<UpdateParameters>
<asparameter Name="ArtworkId" Type="Int32" />
<asparameter Name="Original_ArtworkId" Type="Int32" />
<asparameter Name="ImageURL" Type="string" />
<asparameter Name="Title" Type="string" />
<asparameter Name="Height" Type="int32" />
<asparameter Name="Width" Type="int32" />
<asparameter Name="Depth" Type="int32" />
<asparameter Name="Blurb" Type="string" />
<asparameter Name="ArtistId" Type="int32" />
</UpdateParameters>
<DeleteParameters>
<asparameter Name="Original_ArtworkId" Type="Int32" />
</DeleteParameters>
</asp:ObjectDataSource>


<asp:Label CssClass="sectionHeader" ID="lblArtists"
runat="server">Artists</asp:Label>
<asp:GridView ID="grdArtists" DataSourceID="odsArtists" runat="server"
AutoGenerateColumns="False"
OnRowCommand="grdArtists_RowCommand" DataKeyNames="ArtistId"
AllowSorting="True"
OnSelectedIndexChanged="grdArtists_SelectedIndexCh anged" >
<Columns>
<asp:CommandField ShowInsertButton="True" ShowEditButton="True"
ShowDeleteButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="ArtistId" HeaderText="Artist Id"
SortExpression="ArtistId" />
<asp:BoundField DataField="FirstName" HeaderText="First Name"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last Name"
SortExpression="LastName" />
<asp:BoundField DataField="DisplayName" HeaderText="Display Name"
SortExpression="DisplayName" />
<asp:BoundField DataField="Profile" HeaderText="Profile"
SortExpression="Profile" />
<asp:BoundField DataField="DisplayArtId" HeaderText="DisplayArtId"
SortExpression="DisplayArtId" Visible="False" />
<%-- THIS WORKS --%>
<%--<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="textbox1" Text='<%# Bind("DisplayArtId") %>'
runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="textbox1" Text='<%# Bind("DisplayArtId") %>'
runat="server" />
</EditItemTemplate>
</asp:TemplateField>--%>

<%-- THIS DOES NOT --%>
<asp:TemplateField HeaderText="Display Art"
SortExpression="DisplayArtId">
<EditItemTemplate>
<aspropDownList ID="ddlDisplayArt" AppendDataBoundItems="True"
SelectedValue='<%# Bind("DisplayArtID") %>'
DataSourceID="odsAllArtwork" DataValueField="ArtworkId"
Enabled="true" DataTextField="Title" runat="server" >
<asp:ListItem Text="None" Value="0" />
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<aspropDownList ID="ddlDisplayArt" AppendDataBoundItems="True"
SelectedValue='<%# Bind("DisplayArtID") %>'
DataSourceID="odsAllArtwork" DataValueField="ArtworkId"
Enabled="false" DataTextField="Title" runat="server" >
<asp:ListItem Text="None" Value="0" />
</aspropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<aspetailsView ID="dtlArtists" DataSourceID="odsArtists"
runat="server" AutoGenerateInsertButton="false"
AutoGenerateRows="false"
DefaultMode="Insert" OnItemInserted="dtlArtists_ItemInserted"
DataKeyNames="ArtistId" OnModeChanged="dtlArtists_ModeChanged">
<Fields>
<asp:BoundField DataField="FirstName" HeaderText="First Name"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last Name"
SortExpression="LastName" />
<asp:BoundField DataField="DisplayName" HeaderText="Display Name"
SortExpression="DisplayName" />
<asp:BoundField DataField="Profile" HeaderText="Profile"
SortExpression="Profile" />
<asp:BoundField DataField="DisplayArtId" HeaderText="Display Art
Id" SortExpression="DisplayArtId" />
<asp:CommandField ShowCancelButton="true" ShowInsertButton="true" /
>

</Fields>
</aspetailsView>
</EmptyDataTemplate>
</asp:GridView>

<asp:Label CssClass="sectionHeader" ID="lblArtwork"
runat="server">Artwork</asp:Label>
<asp:GridView ID="grdArtwork" DataSourceID="odsArtwork" runat="server"
AutoGenerateColumns="false"
OnRowCommand="grdArtwork_RowCommand" DataKeyNames="ArtworkId"
AllowSorting="True" Visible="false">
<Columns>
<asp:CommandField ShowInsertButton="true" ShowEditButton="true"
ShowDeleteButton="true" ShowSelectButton="True" />
<asp:BoundField DataField="ArtworkId" HeaderText="Artwork Id"
SortExpression="ArtworkId" />
<asp:BoundField DataField="ImageURL" HeaderText="Image URL"
SortExpression="ImageURL" />
<asp:BoundField DataField="Title" HeaderText="Artwork Title"
SortExpression="Title" />
<asp:BoundField DataField="Height" HeaderText="Height"
SortExpression="Height" />
<asp:BoundField DataField="Width" HeaderText="Width"
SortExpression="Width" />
<asp:BoundField DataField="Depth" HeaderText="Depth"
SortExpression="Depth" />
<asp:BoundField DataField="Blurb" HeaderText="Blurb"
SortExpression="Blurb" />
<asp:BoundField DataField="ArtistId" HeaderText="Artist Id"
SortExpression="ArtistId" />
</Columns>
<EmptyDataTemplate>
<aspetailsView ID="dtlArtwork" runat="server"
DataSourceID="odsArtwork"
DefaultMode="Insert" OnItemInserted="dtlArtwork_ItemInserted"
OnModeChanged="dtlArtwork_ModeChanged" DataKeyNames="ArtworkId"
AutoGenerateRows="false" >
<Fields>
<asp:BoundField DataField="ImageURL" HeaderText="Image URL"
SortExpression="ImageURL" />
<asp:BoundField DataField="Title" HeaderText="Artwork Title"
SortExpression="Title" />
<asp:BoundField DataField="Height" HeaderText="Height"
SortExpression="Height" />
<asp:BoundField DataField="Width" HeaderText="Width"
SortExpression="Width" />
<asp:BoundField DataField="Depth" HeaderText="Depth"
SortExpression="Depth" />
<asp:BoundField DataField="Blurb" HeaderText="Blurb"
SortExpression="Blurb" />
<asp:BoundField DataField="ArtistId" HeaderText="Artist Id"
SortExpression="ArtistId" />
<asp:CommandField ShowCancelButton="true" ShowInsertButton="true" /
>

</Fields>
</aspetailsView>
</EmptyDataTemplate>
</asp:GridView>
</asp:Content>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SelectedValue which is invalid because it does not exist in the list of items. far ASP .Net 5 01-14-2012 05:47 PM
Any good solutions for: SelectedValue which is invalid because it does not exist in the list of items? randy.buchholz ASP .Net 4 07-16-2008 03:45 PM
System.ArgumentOutOfRangeException: 'DropDownList' has a SelectedValue which is invalid because it does not exist in the list of items. J055 ASP .Net 4 11-14-2007 03:08 AM
Avoiding "SelectedValue which is invalid because it does not exist in the list of items" Dave ASP .Net 2 06-30-2007 05:15 PM
'dropdownlist' has a selectedvalue which is invalid because it does not exist in the list of items.p sree reddy ASP .Net 2 06-22-2007 02:15 PM



Advertisments