Dim Tree As TreeNode Dim iDBid As Integer Dim iFocus As Integer = 0 strSQL = " select ForumTypeID,ForumTypeName from T_ForumTypeInfo order by ForumTypeID" Right = sqlQry.Query(strSQL) If Right.Rows.Count < 1 Then Exit Sub End If strSQL = " select DefaultTypeID from T_ForumUserRegInfo where UserID=" + Trim(Session("iUserId")) dtResult = sqlQry.Query(strSQL) If dtResult.Rows.Count > 0 Then iDBid = CInt(dtResult.Rows(0).Item("DefaultTypeID")) Else iDBid = 0 End If For iLop = 0 To Right.Rows.Count - 1 Tree = New TreeNode() sClassID = Trim(Right.Rows(iLop).Item("ForumTypeID")) Tree.ID = sClassID Tree.Text = Trim(Right.Rows(iLop).Item("ForumTypeName")) Tree.NavigateUrl = sUrl + "?ForumTypeID=" + sClassID Tree.Target = "main" TreeClass.Nodes.Add(Tree) If iDBid <> 0 Then If iDBid = CInt(Trim(Right.Rows(iLop).Item("ForumTypeID"))) Then iFocus = iLop + 1 End If End If Next If iFocus <> 0 Then TreeClass.SelectedNodeIndex = iFocus //设置焦点 End If
Dim iDBid As Integer
Dim iFocus As Integer = 0
strSQL = " select ForumTypeID,ForumTypeName from T_ForumTypeInfo order by ForumTypeID"
Right = sqlQry.Query(strSQL)
If Right.Rows.Count < 1 Then
Exit Sub
End If strSQL = " select DefaultTypeID from T_ForumUserRegInfo where UserID=" + Trim(Session("iUserId"))
dtResult = sqlQry.Query(strSQL)
If dtResult.Rows.Count > 0 Then
iDBid = CInt(dtResult.Rows(0).Item("DefaultTypeID"))
Else
iDBid = 0
End If For iLop = 0 To Right.Rows.Count - 1
Tree = New TreeNode()
sClassID = Trim(Right.Rows(iLop).Item("ForumTypeID"))
Tree.ID = sClassID
Tree.Text = Trim(Right.Rows(iLop).Item("ForumTypeName"))
Tree.NavigateUrl = sUrl + "?ForumTypeID=" + sClassID
Tree.Target = "main"
TreeClass.Nodes.Add(Tree)
If iDBid <> 0 Then
If iDBid = CInt(Trim(Right.Rows(iLop).Item("ForumTypeID"))) Then
iFocus = iLop + 1
End If
End If
Next If iFocus <> 0 Then
TreeClass.SelectedNodeIndex = iFocus //设置焦点
End If
this.TreeView1.SelectedNodeIndex="0.0.1";
就不认了,应该怎么搞呢?