我正在建立一个网站,我每个循环都需要2.5分钟才能完成。
我想知道是否有人知道如何加快速度。循环中的两个if语句都必须保留在那里。
Protected Sub WebDataGrid1_InitializeRow(sender As Object, e As Infragistics.Web.UI.GridControls.RowEventArgs) Handles WebDataGrid1.InitializeRow
Dim SqlString As String = ""
Dim TerrMapTable As New DataTable
Dim Terr As String = ""
Dim RgnMgr As String = ""
Dim Reg As String = ""
Dim TerrMap As String = ""
For Each GridRecord As GridRecord In WebDataGrid1.Rows
Terr = GridRecord.Items.FindItemByKey("ABAN8").Value
RgnMgr = GridRecord.Items.FindItemByKey("RgnMgr").Value
If Terr < 9000 Then
Terr = "T" & Terr
Else
Terr = "TA1" & Right(Terr, 2)
End If
SqlString = "Select distinct Terr, Region from TerrReg WHERE Terr='" & Terr & "'"
TerrMapTable = OleFun.GetMyDataTableString(SqlString, 4)
If TerrMapTable.Rows.Count <> 0 Then
Reg = TerrMapTable(0)(1)
TerrMap = "<a href=""/Mapper/Territory_Maps/" & Reg & "/" & Terr & "/" & Terr & "-" & Reg & "-" & "Territory.htm"" target=""_Blank""><b>PIC</b></a>"
GridRecord.Items.FindItemByKey("TerrMap").Text = TerrMap
Else
End If
Next
End Sub
答案 0 :(得分:2)
在InitializeRow
的事件处理程序中,我希望为单行调用它,您循环遍历所有行。因此,我怀疑您已将一个应该是线性的操作转换为行数(事件为每一行触发一次,并且仅对该行进行操作)到一个行数为二次方的操作中(对于每一行,你遍历每一行)。
根据活动名称,我认为你根本不应该有For Each
循环。看起来您应该从事件参数中获取适当的行并仅在该行上操作。
答案 1 :(得分:1)
这可能更适合代码审查,但这是我的想法。