techques
asked on
string.isNullOrEmpty(SelectedItem.Value) not work
Hi
I have a drop down list in a aspx form which uses C#.
If I do not choose anything and pressed submit button, it throws nullreference exception.
But, I use the following code to check it in if condition and still not work.
How can I fix it?
I have a drop down list in a aspx form which uses C#.
If I do not choose anything and pressed submit button, it throws nullreference exception.
But, I use the following code to check it in if condition and still not work.
How can I fix it?
string a = this.location.SelectedItem.Value;
if (string.IsNullOrEmpty(this.location.SelectedItem.Value) || this.location.SelectedItem.Value == null || this.location.SelectedItem.Value =="")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or try this.location.SelectedValu e, which returns a string, so you don't need to check for a null reference, as long as you have a valid pointer to your drop down list
ASKER