Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   The 'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive (http://www.velocityreviews.com/forums/t482357-the-selectedindex-and-selectedvalue-attributes-are-mutually-exclusive.html)

Dooman 03-07-2007 05:59 PM

The 'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive
 
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==?= 03-21-2007 02:41 PM

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
>
>


David Wier 03-21-2007 03:17 PM

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" <BobbyCochran@discussions.microsoft.com> wrote in message
news:84AF5BFF-AD02-4265-8AF2-B65157150955@microsoft.com...
> 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
> >
> >




Mark Rae 03-21-2007 03:35 PM

Re: The 'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive
 
"Dooman" <randydeforest@gmail.com> wrote in message
news:1173290371.441371.46890@j27g2000cwj.googlegro ups.com...

> 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...



=?Utf-8?B?Qm9iYnkgQ29jaHJhbg==?= 03-21-2007 03:55 PM

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" <BobbyCochran@discussions.microsoft.com> wrote in message
> news:84AF5BFF-AD02-4265-8AF2-B65157150955@microsoft.com...
> > 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
> > >
> > >

>
>
>


nasskov 10-08-2007 10:20 AM

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 :-)

rabiniak.piotr 03-02-2012 08:56 AM

Quote:

Originally Posted by nasskov (Post 3088983)
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 :-)


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);
}
}


All times are GMT. The time now is 02:15 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.