后台代码:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim ds As New DataSet()
Dim connectionString As String = ConfigurationManager.ConnectionStrings("cydataConnectionString").ConnectionString
Dim objconn = New SqlConnection(connectionString)
Dim adp As SqlDataAdapter = New SqlDataAdapter("select fname,FAccountID,fPARENTID from t_account order by fnumber", objconn)
adp.Fill(ds)
Me.ViewState("ds") = ds
AddTree(0, Nothing)
End If
End Sub
Private Sub AddTree(ByVal ParentID As Integer, ByVal pNode As TreeNode)
Dim ds As DataSet
ds = Me.ViewState("ds")
Dim dvTree As New DataView()
dvTree = New DataView(ds.Tables(0))
dvTree.RowFilter = "fPARENTID = " + ParentID.ToString
Dim Row As DataRowView
For Each Row In dvTree
Dim Node As New TreeNode()
If pNode Is Nothing Then
Node.Text = Row("fname").ToString()
Node.Value = Row("FAccountID").ToString()
TreeView1.Nodes.Add(Node)
Node.SelectAction = TreeNodeSelectAction.SelectExpand
AddTree(Int32.Parse(Row("FAccountID").ToString()), Node)
Else
Node.Text = Row("fname").ToString()
Node.Value = Row("FAccountID").ToString()
pNode.ChildNodes.Add(Node)
Node.SelectAction = TreeNodeSelectAction.SelectExpand
AddTree(Int32.Parse(Row("FAccountID").ToString()), Node)
End If
Next
End Sub数据库约有450条纪录,显示出来却需要20秒钟,请问有啥改善办法?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim ds As New DataSet()
Dim connectionString As String = ConfigurationManager.ConnectionStrings("cydataConnectionString").ConnectionString
Dim objconn = New SqlConnection(connectionString)
Dim adp As SqlDataAdapter = New SqlDataAdapter("select fname,FAccountID,fPARENTID from t_account order by fnumber", objconn)
adp.Fill(ds)
Me.ViewState("ds") = ds
AddTree(0, Nothing)
End If
End Sub
Private Sub AddTree(ByVal ParentID As Integer, ByVal pNode As TreeNode)
Dim ds As DataSet
ds = Me.ViewState("ds")
Dim dvTree As New DataView()
dvTree = New DataView(ds.Tables(0))
dvTree.RowFilter = "fPARENTID = " + ParentID.ToString
Dim Row As DataRowView
For Each Row In dvTree
Dim Node As New TreeNode()
If pNode Is Nothing Then
Node.Text = Row("fname").ToString()
Node.Value = Row("FAccountID").ToString()
TreeView1.Nodes.Add(Node)
Node.SelectAction = TreeNodeSelectAction.SelectExpand
AddTree(Int32.Parse(Row("FAccountID").ToString()), Node)
Else
Node.Text = Row("fname").ToString()
Node.Value = Row("FAccountID").ToString()
pNode.ChildNodes.Add(Node)
Node.SelectAction = TreeNodeSelectAction.SelectExpand
AddTree(Int32.Parse(Row("FAccountID").ToString()), Node)
End If
Next
End Sub数据库约有450条纪录,显示出来却需要20秒钟,请问有啥改善办法?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货