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

Discussion in 'ASP .Net' started by Jason, Aug 7, 2007.

  1. Jason

    Jason Guest

    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.PerformDataBinding(IEnumerable
    dataSource) +1822067
    System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e)
    +104
    System.Web.UI.WebControls.ListControl.PerformSelect() +31
    System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +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.CreateChildControls(IEnumerable
    dataSource, Boolean dataBinding) +3004

    System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable
    data) +59
    System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable
    data) +11

    System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable
    data) +111
    System.Web.UI.DataSourceView.Select(DataSourceSelectArguments
    arguments, DataSourceViewSelectCallback callback) +29
    System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
    System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
    System.Web.UI.WebControls.GridView.DataBind() +4
    System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
    +82

    System.Web.UI.WebControls.CompositeDataBoundControl.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.ArtistTableAdapter"
    runat="server"
    SelectMethod="GetArtists" UpdateMethod="Update" DeleteMethod="Delete"
    InsertMethod="Insert"
    OldValuesParameterFormatString="original_{0}" >
    <InsertParameters>
    <asp:parameter Name="FirstName" Type="string" />
    <asp:parameter Name="LastName" Type="string" />
    <asp:parameter Name="DisplayName" Type="string" />
    <asp:parameter Name="Profile" Type="string" />
    <asp:parameter Name="DisplayArtId" Type="int32" />
    </InsertParameters>
    <UpdateParameters>
    <asp:parameter Name="Original_ArtistId" Type="Int32" />
    <asp:parameter Name="ArtistId" Type="int32" />
    <asp:parameter Name="FirstName" Type="string" />
    <asp:parameter Name="LastName" Type="string" />
    <asp:parameter Name="DisplayName" Type="string" />
    <asp:parameter Name="Profile" Type="string" />
    <asp:parameter Name="DisplayArtId" Type="int32" />
    </UpdateParameters>
    <DeleteParameters>
    <asp:parameter Name="Original_ArtistId" Type="int32" />
    </DeleteParameters>
    </asp:ObjectDataSource>

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

    <asp:ObjectDataSource ID="odsArtwork"
    TypeName="TurningPointGalleryTableAdapters.ArtworkTableAdapter"
    runat="server" SelectMethod="GetArtworkByArtistId"
    InsertMethod="Insert" UpdateMethod="Update" DeleteMethod="Delete"
    OldValuesParameterFormatString="original_{0}">
    <SelectParameters>
    <asp:ControlParameter Name="ArtistId" ControlID="grdArtists"
    PropertyName="SelectedValue" />
    </SelectParameters>
    <InsertParameters>
    <asp:parameter Name="ImageURL" Type="string" />
    <asp:parameter Name="Title" Type="string" />
    <asp:parameter Name="Height" Type="int32" />
    <asp:parameter Name="Width" Type="int32" />
    <asp:parameter Name="Depth" Type="int32" />
    <asp:parameter Name="Blurb" Type="string" />
    <asp:parameter Name="ArtistId" Type="int32" />
    </InsertParameters>
    <UpdateParameters>
    <asp:parameter Name="ArtworkId" Type="Int32" />
    <asp:parameter Name="Original_ArtworkId" Type="Int32" />
    <asp:parameter Name="ImageURL" Type="string" />
    <asp:parameter Name="Title" Type="string" />
    <asp:parameter Name="Height" Type="int32" />
    <asp:parameter Name="Width" Type="int32" />
    <asp:parameter Name="Depth" Type="int32" />
    <asp:parameter Name="Blurb" Type="string" />
    <asp:parameter Name="ArtistId" Type="int32" />
    </UpdateParameters>
    <DeleteParameters>
    <asp:parameter 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_SelectedIndexChanged" >
    <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>
    <asp:DropDownList ID="ddlDisplayArt" AppendDataBoundItems="True"
    SelectedValue='<%# Bind("DisplayArtID") %>'
    DataSourceID="odsAllArtwork" DataValueField="ArtworkId"
    Enabled="true" DataTextField="Title" runat="server" >
    <asp:ListItem Text="None" Value="0" />
    </asp:DropDownList>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:DropDownList ID="ddlDisplayArt" AppendDataBoundItems="True"
    SelectedValue='<%# Bind("DisplayArtID") %>'
    DataSourceID="odsAllArtwork" DataValueField="ArtworkId"
    Enabled="false" DataTextField="Title" runat="server" >
    <asp:ListItem Text="None" Value="0" />
    </asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    <EmptyDataTemplate>
    <asp:DetailsView 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>
    </asp:DetailsView>
    </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>
    <asp:DetailsView 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>
    </asp:DetailsView>
    </EmptyDataTemplate>
    </asp:GridView>
    </asp:Content>
    Jason, Aug 7, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page