My aspx.vb page has this statement: -
ddlRefTable.SelectedValue = trcolumns.GCLDetails
This was giving me an error message: -
'ddlRefTable' has a SelectedValue which is invalid because it does not exist in the list of items.
Trcolumns.GCLDetails had value "Newspapers". Yet I could see "NewsPapers" in the list of values, and the first line of my page was "Option Compare Text" so it should use text comparison, not binary.
The problem went away when I changed the database value that is read into trcolumns.GCLDetails to "NewsPapers". However I shouldn't have had to do this. Why doesn't the DropDownList use the Option Compare setting/What do I have to do to make it do so?
Yet I could see "NewsPapers" in the list of values
It may be there when you see it, But the listItem 'NewsPapers may not be there or the DropDownList may be empty when that line of code get executed. That generates the error. Can you show how and when you populate the DDL and in which event you write the
code "ddlRefTable.SelectedValue = trcolumns.GCLDetails" ?
Kindly mark this post as "Answer", if it helped you.
I could see "NewsPapers" in the list of values that were in the DDL's data list at the point of failure. For debugging I put the statement within a Try/Catch, and within the Catch I examined the values of the DDL's Items.Item(n).Tostring.
"NewsPapers" was the 15th (of 25) values. The problem went away when I changed the comparison value to "Newspapers". As I mentioned above, the issue is simply that the statement is using an Option Compare Binary comparison even though my VB starts with Option
Compare Text.
This means that everywhere within this page comparisons should use text comparison, not binary comparison. Thus "NewsPapers" and "Newspapers" should compare equal. I should not need to use use string.compare(Str1, Str2, False). In fact I'm not sure how
I could use this, since the comparison is not explicit but is implied by the assignment
ddlRefTable.SelectedValue = trcolumns.GCLDetails
BTW, Option Compare is VB specific, there is no C# equivalent as far as I know.
Sorry, I don't know the Option Compare in vb. The fact is two texts don't compare equal. If you use the exact same text to test, I believe it can pass. I think that's the problem. You think they should be equal, but system doesn't. Why not change both texts
to upper or lower case to compare.
Robert Barne...
Member
451 Points
708 Posts
DropDownList fails (Selected Value not in list) because it is using Compare Binary
Apr 07, 2012 12:57 AM|LINK
My aspx.vb page has this statement: -
ddlRefTable.SelectedValue = trcolumns.GCLDetails
This was giving me an error message: -
'ddlRefTable' has a SelectedValue which is invalid because it does not exist in the list of items.
Trcolumns.GCLDetails had value "Newspapers". Yet I could see "NewsPapers" in the list of values, and the first line of my page was "Option Compare Text" so it should use text comparison, not binary.
The problem went away when I changed the database value that is read into trcolumns.GCLDetails to "NewsPapers". However I shouldn't have had to do this. Why doesn't the DropDownList use the Option Compare setting/What do I have to do to make it do so?
Thank you, Robert.
basheerkal
Star
10672 Points
2426 Posts
Re: DropDownList fails (Selected Value not in list) because it is using Compare Binary
Apr 07, 2012 01:45 AM|LINK
It may be there when you see it, But the listItem 'NewsPapers may not be there or the DropDownList may be empty when that line of code get executed. That generates the error. Can you show how and when you populate the DDL and in which event you write the code "ddlRefTable.SelectedValue = trcolumns.GCLDetails" ?
(Talk less..Work more)
Robert Barne...
Member
451 Points
708 Posts
Re: DropDownList fails (Selected Value not in list) because it is using Compare Binary
Apr 07, 2012 05:22 AM|LINK
I could see "NewsPapers" in the list of values that were in the DDL's data list at the point of failure. For debugging I put the statement within a Try/Catch, and within the Catch I examined the values of the DDL's Items.Item(n).Tostring. "NewsPapers" was the 15th (of 25) values. The problem went away when I changed the comparison value to "Newspapers". As I mentioned above, the issue is simply that the statement is using an Option Compare Binary comparison even though my VB starts with Option Compare Text.
basheerkal
Star
10672 Points
2426 Posts
Re: DropDownList fails (Selected Value not in list) because it is using Compare Binary
Apr 07, 2012 01:27 PM|LINK
OK, agreed. Mark the thread as resolved.
(Talk less..Work more)
Robert Barne...
Member
451 Points
708 Posts
Re: DropDownList fails (Selected Value not in list) because it is using Compare Binary
Apr 07, 2012 09:39 PM|LINK
So why doesn't it use the correct form of comparison according to the Option Compare statement? How do I make it do so?
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: DropDownList fails (Selected Value not in list) because it is using Compare Binary
Apr 10, 2012 08:19 AM|LINK
Hi,
They are two different values for "NewsPapers" and "Newspapers", so the error happens. What do you mean the Option Compare.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
Robert Barne...
Member
451 Points
708 Posts
Re: DropDownList fails (Selected Value not in list) because it is using Compare Binary
Apr 10, 2012 01:26 PM|LINK
As I said in my first posting: -
Line 1 of my aspx.vb page is
Option Compare Text
This means that everywhere within this page comparisons should use text comparison, not binary comparison. Thus "NewsPapers" and "Newspapers" should compare equal. I should not need to use use string.compare(Str1, Str2, False). In fact I'm not sure how I could use this, since the comparison is not explicit but is implied by the assignment
ddlRefTable.SelectedValue = trcolumns.GCLDetails
BTW, Option Compare is VB specific, there is no C# equivalent as far as I know.
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: DropDownList fails (Selected Value not in list) because it is using Compare Binary
Apr 11, 2012 01:15 AM|LINK
Hi,
Sorry, I don't know the Option Compare in vb. The fact is two texts don't compare equal. If you use the exact same text to test, I believe it can pass. I think that's the problem. You think they should be equal, but system doesn't. Why not change both texts to upper or lower case to compare.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework