468,119 Members | 1,910 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,119 developers. It's quick & easy.

'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive (part 2)

Hi all,

I've come back to this problem again and I've identified which part of
my code is producing the error:

"'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive"
I have a dropdown 'Year' and it contains a list of years from 2000 to
2005. This dropdown is populated on page load.

When I select an article to edit (which has a year value associated), I
select the appropriate year dropdown value as follows...

ddYear.SelectedValue = objRS("VYear")
This is causing the above error, I THINK it's because the 'VYear' value
is an integer as opposed to a string.

I've also tried: ddYear.SelectedValue = CInt(objRS("VYear"))
and ddYear.SelectedValue = CStr(objRS("VYear"))

with the same error resulting.

Any ideas?

Thanks.
Peter
--

"I hear ma train a comin'
.... hear freedom comin"

Nov 19 '05 #1
5 9853
Does this work?

Dim li As ListItem = ddYear.Items.FindByValue(CStr(objRS("VYear")))
If Not li Is Nothing Then
li.Selected = True
End If

Greg
"Stimp" <re*@spumco.com> wrote in message
news:sl****************@carbon.redbrick.dcu.ie...
Hi all,

I've come back to this problem again and I've identified which part of
my code is producing the error:

"'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive"
I have a dropdown 'Year' and it contains a list of years from 2000 to
2005. This dropdown is populated on page load.

When I select an article to edit (which has a year value associated), I
select the appropriate year dropdown value as follows...

ddYear.SelectedValue = objRS("VYear")
This is causing the above error, I THINK it's because the 'VYear' value
is an integer as opposed to a string.

I've also tried: ddYear.SelectedValue = CInt(objRS("VYear"))
and ddYear.SelectedValue = CStr(objRS("VYear"))

with the same error resulting.

Any ideas?

Thanks.
Peter
--

"I hear ma train a comin'
... hear freedom comin"

Nov 19 '05 #2
On Tue, 8 Nov 2005 Greg Burns <bl*******@newsgroups.nospam> wrote:
Does this work?

Dim li As ListItem = ddYear.Items.FindByValue(CStr(objRS("VYear")))
If Not li Is Nothing Then
li.Selected = True
End If

Greg


doesn't seem to... is there a way to set the SelectedIndex instead of
the SelectedValue if all I have is the text value?

--

"I hear ma train a comin'
.... hear freedom comin"

Nov 19 '05 #3
Put a breakpoint on "li.Selected = True". Does the debugger ever even get
there? If not, then it is not even finding that value in your current
listitems, hence cannot select it.
"Stimp" <re*@spumco.com> wrote in message
news:sl****************@carbon.redbrick.dcu.ie...
On Tue, 8 Nov 2005 Greg Burns <bl*******@newsgroups.nospam> wrote:
Does this work?

Dim li As ListItem = ddYear.Items.FindByValue(CStr(objRS("VYear")))
If Not li Is Nothing Then
li.Selected = True
End If

Greg


doesn't seem to... is there a way to set the SelectedIndex instead of
the SelectedValue if all I have is the text value?

--

"I hear ma train a comin'
... hear freedom comin"

Nov 19 '05 #4
On Tue, 8 Nov 2005 Greg Burns <bl*******@newsgroups.nospam> wrote:
Put a breakpoint on "li.Selected = True". Does the debugger ever even get
there? If not, then it is not even finding that value in your current
listitems, hence cannot select it.


my mistake, it DOES indeed work.. the new error I was receiving was
separate to the original problem, which your code fixed.

Thanks!

It's still very unusual that you need to use this method to set the
selectedvalue when the text field in your dropdownlist is numerical
*shrug*
--

"I hear ma train a comin'
.... hear freedom comin"

Nov 19 '05 #5
Not sure I understand, but the Value and Text property of you ListItem are
both strings. You have to convert whatever object you want to be a ListItem
into a string to add it to the collection.

ddYear.Items.Insert(0, New ListItem("displayedtext", "actualvalue"))

This code insert in position 0 a new new ListItem. The constructor for
ListItem only takes strings.

To tell you the truth, I am not sure why you are having a problem with:

ddYear.SelectedValue = objRS("VYear").ToString

Greg
"Stimp" <re*@spumco.com> wrote in message
news:sl****************@carbon.redbrick.dcu.ie...
On Tue, 8 Nov 2005 Greg Burns <bl*******@newsgroups.nospam> wrote:
Put a breakpoint on "li.Selected = True". Does the debugger ever even
get
there? If not, then it is not even finding that value in your current
listitems, hence cannot select it.


my mistake, it DOES indeed work.. the new error I was receiving was
separate to the original problem, which your code fixed.

Thanks!

It's still very unusual that you need to use this method to set the
selectedvalue when the text field in your dropdownlist is numerical
*shrug*
--

"I hear ma train a comin'
... hear freedom comin"

Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Tony | last post: by
2 posts views Thread by arun | last post: by
reply views Thread by katmagic | last post: by
13 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.