Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is Empty or Null
Message
From
20/03/2008 10:01:33
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 2.0
OS:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01303548
Message ID:
01303863
Views:
10
This message has been marked as a message which has helped to the initial question of the thread.
So, I don't know if the ASP ListBox works similarly to the WinForm ListBox, but if it does, what you should actually be checking to see if an item was selected in the ListBox is the .SelectedIndex property. It will -1 if nothing has been selected in the ListBox ... you can also set it to -1 initially.

I always say that the controls for ASP and WinForms behave so differently that I shouldn't answer any questions about them at all. But I was halfway through this thread before I realized that you were talking about ASP. <g> So, I may be wrong about a web ListBox ...

~~Bonnie



>Hi everybody,
>
>Ok, another beginner question today.
>
>I'm looking at the following code:
>
> if ((this.lsbUsers.SelectedItem != null || this.lsbUsers.Text != string.Empty)
>            && this.LsbRoles.SelectedValue != null)
>
>and although I'm not selecting anything in lsbRoles it's going inside this block of code producing the error.
>
>I see that the SelectedValue is an empty string in the watch window. So, my first guess was that I need to be able to test for both conditions (empty and null).
>
>Googling led me to string.IsEmptyAndNull method, but then I hit this
>http://msmvps.com/blogs/bill/archive/2006/04/04/89234.aspx
>
>So, do you think it's OK to use this method in code or rather use two comparisions instead?
>
>Thanks a lot in advance.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform