使用递归来建立层次结构。
此递归在 windows server 2003 + IIS6 中运行良好,但在 windows server 2008 R2 和 IIS 7.0 中抛出异常
这是代码片段:
Public Sub Expand(ByVal SE_Index As Int64)
Dim row As DataRow
If aryHierarchyData(SE_Index).Visable = True Then
aryHierarchyData(SE_Index).Target_Row = gvCurrent_Row_Number
gvCurrent_Row_Number = gvCurrent_Row_Number + 1
Try
row = dtExpand.NewRow
row("SE_NO") = aryHierarchyData(SE_Index).SE_No
row("Selection_Index") = aryHierarchyData(SE_Index).Selection_Index
**dtExpand.Rows.Add(row)**--->>>throwing error "stackoverflow"
Catch ex As StackOverflowException
If (ex.Message.Contains("Column 'SE_NO, Selection_Index' is constrained to be unique.")) Then
Exit Sub
End If
Catch ex As Exception
Finally
row = Nothing
End Try
' expand this SE's children - first
If aryHierarchyData(SE_Index).Child > 0 Then
Expand(aryHierarchyData(SE_Index).Child)
End If
End If
' expand this SE's Siblings - second
If aryHierarchyData(SE_Index).Sibling > 0 Then
Expand(aryHierarchyData(SE_Index).Sibling)
End If
End Sub