Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > 'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive (part 2)

Reply
Thread Tools

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

 
 
Stimp
Guest
Posts: n/a
 
      11-08-2005
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"

 
Reply With Quote
 
 
 
 
Greg Burns
Guest
Posts: n/a
 
      11-08-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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"
>



 
Reply With Quote
 
 
 
 
Stimp
Guest
Posts: n/a
 
      11-08-2005
On Tue, 8 Nov 2005 Greg Burns <(E-Mail Removed)> 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"

 
Reply With Quote
 
Greg Burns
Guest
Posts: n/a
 
      11-08-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Tue, 8 Nov 2005 Greg Burns <(E-Mail Removed)> 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"
>



 
Reply With Quote
 
Stimp
Guest
Posts: n/a
 
      11-08-2005
On Tue, 8 Nov 2005 Greg Burns <(E-Mail Removed)> 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"

 
Reply With Quote
 
Greg Burns
Guest
Posts: n/a
 
      11-08-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Tue, 8 Nov 2005 Greg Burns <(E-Mail Removed)> 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"
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The 'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive Dooman ASP .Net 6 03-02-2012 08:56 AM
Has 2.0 Fixed this 1.1 bug? Radio Buttons Are Not Mutually Exclusive When Used in a Repeater Server Control sloan@ipass.net ASP .Net 0 01-06-2006 09:23 PM
'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive Stimp ASP .Net 2 10-24-2005 01:53 PM
mutually exclusive radio button js ASP .Net 2 05-19-2005 04:27 PM
Mutually exclusive ALuPin VHDL 2 09-07-2004 04:41 PM



Advertisments