We help IT Professionals succeed at work.
Get Started

Dynamic Gridview hyperlink problem

245 Views
Last Modified: 2015-01-22
So I'm adding columns and rows dynamically to a DataTable but it just seems to be impossible to include a hyperlink in the data. Its like the <A> tag is explicitly rejected inside the gridview when it is presented.

I know the approved way to do this is to add hyperlink fields to the gridview control in the HTML but because this is built so dynamically (requires various columns/rows) - I don't think thats possible

Here is the sub....



    Private Sub MakeLeagueSummaryGrid(ByVal leaguename As String, ByVal totalTeams As Integer, ByVal totalScheduledGames As Integer)
        Dim totalmatches As Integer = totalTeams / 2
        Dim NoOfWeeks As Integer = 0
        Try
            NoOfWeeks = totalScheduledGames / totalmatches

        Catch ex As Exception
            NoOfWeeks = 0
        End Try


        Dim dt As New DataTable
        Dim dcRound As New DataColumn("Round", GetType(Integer))
        Dim dcDate As New DataColumn("Date Played", GetType(String))

       
        dt.Columns.Add(dcRound)
        dt.Columns.Add(dcDate)


       

        For i As Integer = 0 To totalmatches - 1
            dt.Columns.Add(New DataColumn("Game #" & (i + 1), GetType(String)))

        Next

        Dim drow As DataRow

        For weekcount = 0 To NoOfWeeks * 2 + 1
            drow = dt.NewRow
            If dt.Rows.Count >= weekcount - 2 Then
                drow.Item("Round") = weekcount + 1
            End If



            dt.Rows.Add(drow)

        Next

        Dim db As New SQLiteEntities

        Dim str As String = "select ZhTeamName ||  "";;;;"" || z.ZHDATE ||  "";;;;"" || ZhFinalScore ||  "";;;;"" || ZHTIMEELAPSED from ZHISTORYTEAM zh, Zhistory z   where zh.ZHISTORY = z.Z_PK and z.ZHSeason = (select  ZHSeason from Zhistory Order by ZHseason desc limit 1)  AND ZHLEAGUENAME ='" & leaguename & "' order by z.[ZHDATE] asc "
        Dim hst = db.ExecuteStoreQuery(Of String)(str).ToList()

        Dim rowNo As Integer = 0
        Dim teamResult As String = ""
        Dim rowNumber As Integer = -1
        Dim colNumber As Integer = 1
        Dim curDate As Date = "1/1/1900"
        Dim isFirstEmptyRow As Boolean = False
        'Dim grp = hst.GroupBy(Function(x) x.Id, Function(x) x.Name)
        For Each grp In hst



            Dim Group() As String = grp.ToString().Split(";;;;")
            If (rowNo Mod 2 = 0) Then

                If (Group(12) > 0) Then
                    teamResult = Group(0) & " " & Group(8)
                Else
                    teamResult = Group(0) & " "
                End If


                'drow = dt.NewRow
                'drow("Id") = Group(0)
                'drow("Team 1") = Group(4)
                'drow("Match Date") = UnixTimeStampToDateTime(Group(8))
                'drow("Score 1") = Group(12)
                'drow("Details") = Group(16)
                'Dim words() As String

                'words = drow("Name").ToString().Split(";;;;")
                'Dim dtDate As DateTime = UnixTimeStampToDateTime(words(4)).Date
                'drow("Name") = dtDate + " , " + words(0)


            Else
                If (Group(12) > 0) Then
                    teamResult = teamResult & " vs " & Group(0) & " " & Group(8)
                    Dim dtDate As Date = Date.Parse(UnixTimeStampToDateTime(Group(4)))

                    If curDate.ToShortDateString() <> dtDate.ToShortDateString() Then
                        curDate = dtDate.ToShortDateString()
                        rowNumber = rowNumber + 1
                    End If
                    colNumber = colNumber + 1
                    dt.Rows(rowNumber).BeginEdit()
                    Dim dateString = dtDate.ToShortDateString()
                    dt.Rows(rowNumber).Item(1) = dateString
                    ' dt.Rows(rowNumber).Item(colNumber) = "<<a href=""GameStatDetails.aspx?Id=185&amp;team1=Doomsday Bunnies&amp;team2=B.I.A.C""> " & teamResult & "</a>" 'this is where the socres are added and I want to add link to game

                    ' dt.Rows(rowNumber).Item(2).navigateURL =
                    'colNumber.NavigateUrl = "~\views\view_prospect.aspx?id=" & dt.Rows(column index).Item("ID").ToString

                    Dim testlink = "<a href='simple'>AAAA</a>"

                    dt.Rows(rowNumber).Item(colNumber) = teamResult & testlink



                    'dt.Rows(rowNumber).Item(colNumber) = "<A href='simple'>AAAA</>"

                    '  dt.Rows(rowNumber).Item(colNumber).navigateURL = "GameStatDetails.aspx?Id=185&amp;team1=Doomsday Bunnies&amp;team2=B.I.A.C"

                    dt.Rows(rowNumber).Item("Round") = rowNumber + 1
                    dt.Rows(rowNumber).EndEdit()
                    teamResult = ""
                    If colNumber = dt.Columns.Count - 1 Then
                        colNumber = 1
                    End If
                Else
                    If (isFirstEmptyRow = False) Then
                        rowNumber = rowNumber + 1
                        isFirstEmptyRow = True
                    End If
                    teamResult = teamResult & " vs " & Group(0)
                    Dim dtDate As Date = Date.Parse(UnixTimeStampToDateTime(Group(4)))




                    colNumber = colNumber + 1
                    dt.Rows(rowNumber).BeginEdit()
                    Dim dateString = dtDate.ToShortDateString()
                    dt.Rows(rowNumber).Item(1) = ""
                    dt.Rows(rowNumber).Item(colNumber) = teamResult
                    dt.Rows(rowNumber).Item("Round") = rowNumber + 1
                    dt.Rows(rowNumber).EndEdit()
                    teamResult = ""
                    If colNumber = dt.Columns.Count - 1 Then
                        colNumber = 1
                        rowNumber = rowNumber + 1
                    End If
                End If





                'If drow("Score 1") <> drow("Score 2") Then
                '    drow("Result") = drow("Team 1") + vbTab + drow("Score 1") + "  -  " + drow("Team 2") + "   " + drow("Score 2")
                'Else
                '    drow("Result") = "Mtach drawn with " + drow("Score 1") + " - " + drow("Score 2")
                'End If




            End If


            rowNo = rowNo + 1

        Next

        If dt.Rows.Count > 2 Then
            DeleteFromDataTable(dt, "[Game #1] IS NULL")
        End If


        Dim actualRoundnumber As Integer = 0
        For i As Integer = 0 To dt.Rows.Count - 1
            Try
                If dt.Rows(i).Item("Date Played") = "" Then
                    dt.Rows(i).BeginEdit()
                    dt.Rows(i).Item("Round") = dt.Rows.Count - i
                    dt.Rows(i).EndEdit()
                Else
                    actualRoundnumber = actualRoundnumber + 1
                    dt.Rows(i).BeginEdit()
                    dt.Rows(i).Item("Round") = actualRoundnumber
                    dt.Rows(i).EndEdit()
                End If
            Catch ex As Exception

            End Try


        Next



        dt.DefaultView.Sort = "[Round] ASC"





        grdLeagueSummary.DataSource = dt.DefaultView
        grdLeagueSummary.DataBind()
    End Sub
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE