I am making a website and I have a for each loop that is taking 2.5 minutes to run through.
I am wondering if anyone knows how i can speed it up. Both of the if statements inside of the loop have to remain there.
 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