.net dropdownlist if condition
I had posted this question before but didn't 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 noth开发者_高级运维ing 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 don't 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
If Not String.IsNullOrEmpty(date1.sSelectedValue) Then
insexp = DateTime.ParseExact(date1.SelectedValue, "MMMM yyyy", provider)
End If
Check selectedindex instead of selectedvalue
精彩评论