The 'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive

Discussion in 'ASP .Net' started by Dooman, Mar 7, 2007.

  1. Dooman

    Dooman Guest

    Hello,

    I am getting this error when binding a drop down list box to a
    dataset:

    The 'SelectedIndex' and 'SelectedValue' attributes are mutually
    exclusive

    I have looked at other posts and they al refer to this error when
    accessing data in the list box.

    Any ideas?

    Thanks!
    Randy DeForest
     
    Dooman, Mar 7, 2007
    #1
    1. Advertising

  2. RE: The 'SelectedIndex' and 'SelectedValue' attributes are mutually ex

    I am having this same problem when filling a drop down list. Did you ever
    find a solution to this? Any help would be appreciated.

    "Dooman" wrote:

    > Hello,
    >
    > I am getting this error when binding a drop down list box to a
    > dataset:
    >
    > The 'SelectedIndex' and 'SelectedValue' attributes are mutually
    > exclusive
    >
    > I have looked at other posts and they al refer to this error when
    > accessing data in the list box.
    >
    > Any ideas?
    >
    > Thanks!
    > Randy DeForest
    >
    >
     
    =?Utf-8?B?Qm9iYnkgQ29jaHJhbg==?=, Mar 21, 2007
    #2
    1. Advertising

  3. Dooman

    David Wier Guest

    Re: The 'SelectedIndex' and 'SelectedValue' attributes are mutually ex

    What kind of error are you receiving?
    It would be helpful to know exactly what the error says - and then, possibly
    your code for population.

    --
    David Wier
    MVP/ASPInsider
    http://aspnet101.com
    http://aspexpress.com



    "Bobby Cochran" <> wrote in message
    news:...
    > I am having this same problem when filling a drop down list. Did you ever
    > find a solution to this? Any help would be appreciated.
    >
    > "Dooman" wrote:
    >
    > > Hello,
    > >
    > > I am getting this error when binding a drop down list box to a
    > > dataset:
    > >
    > > The 'SelectedIndex' and 'SelectedValue' attributes are mutually
    > > exclusive
    > >
    > > I have looked at other posts and they al refer to this error when
    > > accessing data in the list box.
    > >
    > > Any ideas?
    > >
    > > Thanks!
    > > Randy DeForest
    > >
    > >
     
    David Wier, Mar 21, 2007
    #3
  4. Dooman

    Mark Rae Guest

    "Dooman" <> wrote in message
    news:...

    > I am getting this error when binding a drop down list box to a
    > dataset:
    >
    > The 'SelectedIndex' and 'SelectedValue' attributes are mutually
    > exclusive
    >
    > I have looked at other posts and they al refer to this error when
    > accessing data in the list box.


    Yes indeed - I've seen this error before when tying to select a ListItem
    programmatically, but never during databinding...

    As has already been mentioned, please post your code...
     
    Mark Rae, Mar 21, 2007
    #4
  5. Re: The 'SelectedIndex' and 'SelectedValue' attributes are mutuall

    The error is odd, and only happens in one situation with me. I'll post code
    below after I explain. The only time the error happens is when a control
    with the same drop down information and ID on a previous page has a set
    value. For instance, on my listing page I have a filter drop down with id
    m_ddlActivityClass. When I select a filter value from that drop down and
    postback, the list is altered. At that point, I choose an item from the
    filtered list (gridview) to move to another page with detail of that item.
    This page is called through a <a> link and never posts anything back, just
    passes an ID with it for the next page. It is the next page that causes this
    error:

    The 'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive.
    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.ArgumentException: The 'SelectedIndex' and
    'SelectedValue' attributes are mutually exclusive.

    Source Error:

    Line 224: m_ddlActivityClass.DataValueField =
    "ActivityClassTypeId";
    Line 225: m_ddlActivityClass.DataTextField = "DisplayTitle";
    Line 226: m_ddlActivityClass.DataBind();
    Line 227: }
    Line 228:

    Again, this only happens when I have selected a value in the drop down on
    the previous page. Otherwise, everything binds just fine. At the point from
    which it crashes, I have not yet tried to set the selected value.

    The code is as follows:

    ActivityClassTypesFactory objFactory = new
    ActivityClassTypesFactory(base.Connection);
    ActivityClassTypesCollection objCollection = objFactory.ShowAll();

    m_ddlActivityClass.DataSource = objCollection;
    m_ddlActivityClass.DataValueField = "ActivityClassTypeId";
    m_ddlActivityClass.DataTextField = "DisplayTitle";
    m_ddlActivityClass.DataBind();

    Thanks for the help!

    Bobby

    "David Wier" wrote:

    > What kind of error are you receiving?
    > It would be helpful to know exactly what the error says - and then, possibly
    > your code for population.
    >
    > --
    > David Wier
    > MVP/ASPInsider
    > http://aspnet101.com
    > http://aspexpress.com
    >
    >
    >
    > "Bobby Cochran" <> wrote in message
    > news:...
    > > I am having this same problem when filling a drop down list. Did you ever
    > > find a solution to this? Any help would be appreciated.
    > >
    > > "Dooman" wrote:
    > >
    > > > Hello,
    > > >
    > > > I am getting this error when binding a drop down list box to a
    > > > dataset:
    > > >
    > > > The 'SelectedIndex' and 'SelectedValue' attributes are mutually
    > > > exclusive
    > > >
    > > > I have looked at other posts and they al refer to this error when
    > > > accessing data in the list box.
    > > >
    > > > Any ideas?
    > > >
    > > > Thanks!
    > > > Randy DeForest
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?Qm9iYnkgQ29jaHJhbg==?=, Mar 21, 2007
    #5
  6. Dooman

    nasskov

    Joined:
    Oct 8, 2007
    Messages:
    1
    I had the same problem, this seems to be a bug in the dropdown list control.
    I lost several hours searching for solution, but didn't found anything, so I had to find a way myself. And here it is:
    Just before the databinding set the .SelectedIndex = -1
    That helps :)
     
    Last edited: Oct 26, 2007
    nasskov, Oct 8, 2007
    #6
  7. Dooman

    rabiniak.piotr

    Joined:
    Mar 2, 2012
    Messages:
    1

    Thank you mate.
    That saved my time :D


    btw: new methods that fixed this problem:

    public static void SetSelectedValue(this ListControl ddl, string value)
    {
    if (ddl.Items.FindByValue(value) != null)
    {
    ddl.SelectedIndex = -1;
    ddl.SelectedValue = value;
    }
    }

    public static void SetSelectedValue(this ListControl ddl, string value, string text)
    {
    if (ddl.Items.FindByValue(value) != null)
    {
    ddl.SelectedIndex = -1;
    ddl.SelectedValue = value;
    }
    else
    {
    var item = new ListItem(text, value);
    item.Selected = true;
    ddl.Items.Add(item);
    }
    }
     
    rabiniak.piotr, Mar 2, 2012
    #7
    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.
Similar Threads
  1. ALuPin

    Mutually exclusive

    ALuPin, Sep 7, 2004, in forum: VHDL
    Replies:
    2
    Views:
    720
    Mike Treseler
    Sep 7, 2004
  2. js
    Replies:
    2
    Views:
    893
  3. Stimp
    Replies:
    2
    Views:
    805
    Stimp
    Oct 24, 2005
  4. Stimp
    Replies:
    5
    Views:
    5,982
    Greg Burns
    Nov 8, 2005
  5. Replies:
    0
    Views:
    623
Loading...

Share This Page