开发者

.net dropdownlist if condition

开发者 https://www.devze.com 2022-12-16 07:44 出处:网络
I had posted this question before but didn\'t get the right answer - here\'s my code again with the 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

0

精彩评论

暂无评论...
验证码 换一张
取 消