Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 8th, 2008, 05:53 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Comparing ListItem objects

Hi All,
I am trying to do a simple check. I have 2 dropdownlists A and B.

I am trying to check whether the Selected Item in B exists in Dropdownlist A using the code below.

Code:
if (A.Items.Contains(B.SelectedItem))
However this is never working, even if the condition is true.

Any thoughts?

 
Old April 8th, 2008, 12:25 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I think what you're checking here is whether a ListItem from one list exists in the other, which is not the case.

Try something like this instead:

If (A.Items.FindByValue(B.SelectedItem.Value) IsNot Nothing)

Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
set tooltiptext on every listitem for Combo myself.panku ASP.NET 1.0 and 1.1 Professional 0 March 18th, 2008 08:57 AM
listitem alyeng2000 ASP.NET 1.0 and 1.1 Basics 2 January 3rd, 2004 10:13 AM
SelectedIndexChange uses ListItem value Randy76 VS.NET 2002/2003 3 September 11th, 2003 09:33 AM
ListView, ListItem problems/questions Tremmorkeep C# 0 July 17th, 2003 04:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.