以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]帮忙看看这个求年龄的代码。(已解决)  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=12398)

--  作者:pc005637
--  发布时间:2011/9/1 13:52:00
--  [求助]帮忙看看这个求年龄的代码。(已解决)
有两列:分别是 出生日期 年龄
代码放在DataColChanged事件上
If e.DataCol.Name = "出生日期" Then
If e.NewValue Is Nothing Then
Return
Else
Dim n As Integer = Date.Today.year - e.NewValue.Year
If e.NewValue.AddMonths(n*12) > Date.Today Then
n = n - 1
e.DataRow("年龄") = n
End If
End If
End If

输入出生日期后不能自动出现年龄,求解。
[此贴子已经被作者于2011-9-1 14:21:44编辑过]

--  作者:狐狸爸爸
--  发布时间:2011/9/1 13:54:00
--  

If e.DataCol.Name = "出生日期" Then
    If e.NewValue Is Nothing Then

        e.DataRow("年龄") = Nothing
    Else
        Dim n As Integer = Date.Today.year - e.NewValue.Year
        If e.NewValue.AddMonths(n*12) > Date.Today Then
            n = n - 1
        End If

        e.DataRow("年龄") = n
    End If
End If


--  作者:pc005637
--  发布时间:2011/9/1 14:21:00
--  谢谢。
谢谢。解决问题。
--  作者:wcs4812
--  发布时间:2011/10/12 9:34:00
--  
顶一下