views:

128

answers:

2

I had posted this question before but didnt get the right answer - here's my code again with the if condition.

Dim provider As CultureInfo = CultureInfo.InvariantCulture 
            Dim a1 As DateTime = Nothing 
if date1.selectedvalue isnot nothing then
            insexp = DateTime.ParseExact(date1.SelectedValue, "MMMM yyyy", provider) 
end if
            If a1.Month = Today.Month AndAlso a1.Year = Today.Year Then 
                a1 = Today.Date 
            End If 

date1 is a dropdownlist in the aspx page and does not have a value if you dont select it. Its not a mandatory dropdownlist. When i run it in debugger mode I get the value of date1 = "". And that goes into the if condition and crashes. Please advice how to make this IF condition work

+2  A: 
If Not String.IsNullOrEmpty(date1.sSelectedValue) Then
    insexp = DateTime.ParseExact(date1.SelectedValue, "MMMM yyyy", provider) 
End If
Josh Stodola
+1  A: 

Check selectedindex instead of selectedvalue

BenB