If e.DataCol.Name = "录入日期" Then
If e.DataRow.IsNull("录入日期") Then
e.DataRow("产品编号") = Nothing
Else
Dim d As Date = e.DataRow("录入日期")
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim fd As Date = New Date(y,m,1)
Dim ld As Date = New Date(y,m,Days)
Dim bh As String = e.datarow("产品类型") & Format(d,"MMdd")
Dim drs As List(of DataRow) = e.DataTable.Select("录入日期 >= #" & fd & "# And 录入日期 <= #" & ld & "#")
For i As Integer = 0 To drs.Count - 1
drs(i)("产品编号") = bh & format(i+1,"000")
Next
End If
End If
现成的例子,自己修改一下吧.