Group29.com - What did you expect?
  Create an account
:: Home  ::  Downloads  ::  Your Account  ::  Forums  ::
Google Adsense
Modules
  • Home
  • Downloads
  • ExpectationReviews
  • Forums
  • Group29 FAQ
  • MovieReviews
  • OtherReviews
  • Stories Archive
  • Submit News
  • Top 10
  • Topics
  • Web Links
  • New at Group29
    ·2017 USC vs UCLA preview
    ·Movie Review: IT (2017) [25]
    ·Movie Review: Dean [20]
    ·Forum Topic: Update your Facebook property
    ·2016 UCLA vs USC preview
    ·Expectation Review: Star Wars: The Force Awakens [29]
    ·Web Link: WEP Key Converter
    ·Expectation Review: Jupiter Ascending [25]
    ·Forum Topic: Why does my IPA file get saved as a zip file in IE?
    ·Web Link: BeyondCompare

    read more...
    TheForce.Net
    ·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

    read more...
    Hot trends
    ·Group29.com

    read more...
    Group29 Discussion Board :: View topic - DropDownList has a SelectedValue which is invalid because
    Log in Register Forum FAQ Memberlist Search
    Ratings, Links, Free Speech and more

    Group29 Discussion Board Forum Index -> Group29 Tech Tips -> DropDownList has a SelectedValue which is invalid because
    Post new topic  Reply to topic View previous topic :: View next topic 
    DropDownList has a SelectedValue which is invalid because
    PostPosted: Thu Nov 09, 2006 4:12 pm Reply with quote
    BB
    Regular
     
    Joined: Jun 23, 2004
    Posts: 340


      


    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:


    Quote:
    System.ArgumentOutOfRangeException: DropDownList1 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
    Code:
     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
    Code:
    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)
        Try
            MydrpEditMgrId.Items.Add(myListItem)
        Catch

        End Try
        Try
            MydrpEditMgrId.SelectedValue = myUserID
        Catch
        End Try

       
    End If
    View user's profile Visit poster's website
    Plan B
    PostPosted: Thu Nov 09, 2006 4:16 pm Reply with quote
    BB
    Regular
     
    Joined: Jun 23, 2004
    Posts: 340


      


    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.
    View user's profile Visit poster's website
    Article moved to main page
    PostPosted: Wed Sep 12, 2007 9:59 am Reply with quote
    BB
    Regular
     
    Joined: Jun 23, 2004
    Posts: 340


      


    This article has been promoted to the main Group29 page because of the number of hits.
    System.ArgumentOutOfRangeException: DropDownList1 has a SelectedValue which is invalid because it does not exist in the list of items.
    View user's profile Visit poster's website
    DropDownList has a SelectedValue which is invalid because
      Group29 Discussion Board Forum Index -> Group29 Tech Tips
    You cannot post new topics in this forum
    You cannot reply to topics in this forum
    You cannot edit your posts in this forum
    You cannot delete your posts in this forum
    You cannot vote in polls in this forum
    All times are GMT - 6 Hours  
    Page 1 of 1  

      
      
     Post new topic  Reply to topic  


    Powered by phpBB © 2001-2003 phpBB Group
    Theme created by Vjacheslav Trushkin
    Forums ©
    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.21 Seconds

    :: HeliusGray phpbb2 style by CyberAlien :: PHP-Nuke theme by www.nukemods.com ::