- What did you expect?
  Create an account
:: Home  ::  Downloads  ::  Your Account  ::  Forums  ::
Google Adsense
  • Home
  • Downloads
  • ExpectationReviews
  • Forums
  • Group29 FAQ
  • MovieReviews
  • OtherReviews
  • Stories Archive
  • Submit News
  • Top 10
  • Topics
  • Web Links
  • New at Group29
    ·Movie Review: Eternals [15]
    ·Tuna Is Not The Favorite Pizza Topping in Minnesota
    ·UCLA vs USC preview 2021
    ·Movie Review: Godzilla vs. Kong (2021) [28]
    ·Expectation Review: Captain Marvel [25]
    ·Expectation Review: Avengers: Infinity War [24]
    ·Forum Topic: Update your Facebook property
    ·Web Link: WEP Key Converter
    ·Forum Topic: Why does my IPA file get saved as a zip file in IE?
    ·Web Link: BeyondCompare

    ·Rebelscum Breast Cancer Awareness Charity Patch
    ·BBC Interviews J.J. Abrams About Trek And Wars
    ·CEII: Jabba's Palace Reunion - Massive Guest Announcements
    ·Fathead's May the Fourth Be With You!
    ·Star Wars Night With The Tampa Bay Storm Reminder
    ·Stephen Hayford Star Wars Weekends Exclusive Art
    ·ForceCast #251: To Spoil or Not to Spoil
    ·New Timothy Zahn Audio Books Coming
    ·SDCC: Exclusive Black Series Boba Fett With Han In Carbonite Set
    ·Star Wars Art Exposition May 4th

    Hot trends

     DropDownList has a SelectedValue which is invalid because it does not exist ...
    What do we know?
    Here is the scenario, I was using a gridview control in visual studio 2005. I had an itemtemplate with a label for the value and an edititemtemplate with a dropdownlist to use to select values. Unfortunately, the actual row in the main table did not have a corresponding entry in the source table for the drop down list. So I got an error:

    System.ArgumentOutOfRangeException: DropDownList1 has a SelectedValue
    which is invalid because it does not exist in the list of items.

    This is one of the popular hits on the Group29 Tech tips forum.
    Group29 Tech Tips forum: DropDownList has a SelectedValue which is invalid because it does not exist in the list of items.

    This is quite a problem if you have not maintained data integrity, and/or if your Select statment in your dropdownlist data source does not include particular values.

    My problem was that my main table had a key in the product manager field for a user in the user table who was not flagged as a product manager.

    After much scratching and fumbling, I eventually decided on two possibilities.

    Plan A.)

    1.) In the RowEditing event, grab the current person from the list and store in a private member variable
    Dim WhichRow As Integer = e.NewEditIndex
    m_SelectedManager = CType(CType(grvProduct.Rows(WhichRow).Cells(4).Controls.Item(1), System.Web.UI.Control), System.Web.UI.WebControls.Label).Text()

    2.) Then use that member variable in a SQL statement to look up the corresponding ID.

    3.) Find the drop down list in the Gridview databinding event and insert the missing item. The rowstate for the edited row will be edit (4) or alternate(1) + edit(4) = 5
    If ((e.Row.RowState = 4) Or (e.Row.RowState = 5)) Then
    Dim MydrpEditMgrId As DropDownList = CType(e.Row.Cells(4).FindControl("drpEditMgrId"), DropDownList)
    Dim myUserID As Integer = GetUserIDbyName(m_SelectedManager)
    Dim myListItem = New ListItem(m_SelectedManager & " *", myUserID)

    End Try
    MydrpEditMgrId.SelectedValue = myUserID
    End Try

    End If

    Plan B.)

    This turned out to be the final solution, because the user was interested in having all the users available. Change the SELECT statement to be a UN-ION of both the source table and the list of all the entries in the main table that would not have appeared in the source table.

    Here is one example that does not use a UN-ION (dash to protect for PHP-Nuke) query, but instead a SELECT IN query.

    asp:SqlDataSource ID="DropDownListProjectManager2" runat="server" ConnectionString="<%$ConnectionStrings:YourConnectionString %>"
    SelectCommand="SELECT [usrName], [usrId] FROM [the_usr_table] WHERE (( ([usrDeleteFlag] = @usrDeleteFlag) AND ([usrStatus] = @usrStatus)) OR ([usrID] in (SELECT [prjdevid] from the_prj_table where prjid = @prjid ))) ORDER BY [usrName]">


    In this example, we were getting an error because the user status of the current user in the user table did not match the required user status to be in the project table. The rule was that a user could be assigned as a project manager on the project even if the status had changed.
    Posted on Wednesday, September 12, 2007 @ 08:57:40 UTC by BB
    "DropDownList has a SelectedValue which is invalid because it does not exist ..." | Login/Create an Account | 0 comments
    The comments are owned by the poster. We aren't responsible for their content.

    No Comments Allowed for Anonymous, please register
    Group29 Productions

    All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest (c) 2006 by Group29 Productions.

    You can syndicate Group29 Productions news with an RSS Feeder using the file backend.php

    PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
    Page Generation: 0.18 Seconds

    :: HeliusGray phpbb2 style by CyberAlien :: PHP-Nuke theme by ::