Create Dynamic Hyperlink to GridView VB \ ASP.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • remya1000
    New Member
    • Apr 2007
    • 115

    Create Dynamic Hyperlink to GridView VB \ ASP.NET

    i'm using VB \ ASP.NET.

    i'm trying to display some values in Gridview. but i don't know how many columns i need to display. at run time only i will come to know how many columns i need to display. it depends up on the values from Database. so i'm creating columns dynamically and adding to gridview. till that it works fine. but i want some columns value to be hyperlink. so i need to create some columns hyperlink dynamically.

    Database table looks like this
    Index-------Name--------------Date-----------------Description
    1------------John----------------12/1/2010---------- Work
    2------------Peter---------------12/2/2010---------- Out
    3------------John----------------12/3/2010---------- Off
    depends upon the "Distinct Date", the number of columns in gridview is created dynamically.

    Gridview looks like this
    Index-----Name----------12/1/2010-------12/2/2010----------12/3/2010
    1----------John-----------Work--------------ADD NEW----------Off
    2----------Peter----------ADD NEW---------Out-----------------ADD NEW
    for all the date columns i want to create dynamic hyperlink.
    for example : if i need to make any chnage for 12/1/2010 john, i can click hyperlink "Work" and update the information. and if i need to add some description for 12/2/2010 John, i can click hyperlink "Add New" and add description for that date.
    Codes
    Code:
    Sub Display_Table
            Dim Table_MAINPAGE As DataTable
            Dim Row As DataRow
            Dim dcol As DataColumn
            Dim myConnection As SqlConnection
            Dim MySQL As String
            Dim myCommand As SqlCommand
            Dim myreader As SqlDataReader
            Dim pFirst As Boolean = True
            Dim Name_NotExist, Group_NotExist As Boolean
    
            aryDate.Clear()
            aryName.Clear()
            aryDate_Desc.Clear()
           
            Table_MAINPAGE = New DataTable()
    
            dcol = New DataColumn(" # ")
            Table_MAINPAGE.Columns.Add(dcol)
    
            dcol = New DataColumn("Name")
            Table_MAINPAGE.Columns.Add(dcol)
    
            myConnection = New SqlConnection(WebConfigurationManager.ConnectionStrings("cvConnectionString").ToString)
            MySQL = "select DISTINCT ondate from sList ORDER BY ondate"
            myConnection.Open()
            myCommand = New SqlCommand(MySQL, myConnection)
            myreader = myCommand.ExecuteReader
            While myreader.Read
                'Get distinct Date from database
                aryDate.Add(myreader(0))
                dcol = New DataColumn(Trim(myreader(0)))
                Table_MAINPAGE.Columns.Add(dcol)
            End While
            myreader.Close()
    
            pFirst = True
            MySQL = "Select fname, lname from Users ORDER BY fname"
            myCommand = New SqlCommand(MySQL, myConnection)
            myreader = myCommand.ExecuteReader
            While myreader.Read
                If pFirst = True Then
                    pFirst = False
                    'Get distinct Name from database
                    aryName.Add(myreader(0) & " " & myreader(1))
                    GoTo NextValue
                End If
    
                Name_NotExist = False
                Group_NotExist = False
                For q As Integer = 0 To aryName.Count - 1
                    If myreader(0) & " " & myreader(1) <> aryName.Item(q) Then
                        Name_NotExist = True
                    Else
                        Name_NotExist = False
                        GoTo NextValue
                    End If
                Next
                If Name_NotExist = True Then
                    aryName.Add(myreader(0) & " " & myreader(1))
                End If
    NextValue:
            End While
            myreader.Close()
    
    
            Dim h As Integer = 0
            Dim gBool As Boolean = False
            'Now add data for dynamic columns
            'As first column is increment, as number of data in database
            'Let's add some data to the other columns
            For k As Integer = 0 To aryName.Count - 1
                aryDate_Desc.Clear()
                MySQL = "select ondate, description from sList where [name] = '" & Trim(aryName.Item(k).ToString) & "' order by ondate"
                myCommand = New SqlCommand(MySQL, myConnection)
                myreader = myCommand.ExecuteReader
                'Create a new row
                Row = Table_MAINPAGE.NewRow()
                h = h + 1
                Row(" # ") = h
                Row("Name") = aryName.Item(k).ToString
                While myreader.Read
                    aryDate_Desc.Add(myreader(0) & " - " & myreader(1))
                End While
                For i As Integer = 0 To aryDate.Count - 1
                    gBool = False
                    For j As Integer = 0 To aryDate_Desc.Count - 1
                        If Trim(aryDate.Item(i)) = Trim(aryDate_Desc.Item(j).Split("-")(0)) Then
                            'Initialize the row data.
                            Row(Trim(aryDate.Item(i))) = Trim(aryDate_Desc.Item(j).Split("-")(1))
                            gBool = True
                            GoTo NextArrayValue
                        End If
                    Next
    NextArrayValue:
                    If gBool <> True Then
                        Row(Trim(aryDate.Item(i))) = "Add New"
                    End If
                Next
                'Add the row to the datatable.
                Table_MAINPAGE.Rows.Add(Row)
                myreader.Close()
            Next
           
            'Initialize the DataSource
            GridView1.DataSource = Table_MAINPAGE
    
            For i As Integer = 0 To GridView1.Columns.Count - 1
                GridView1.Columns(i).ItemStyle.Width = 500
            Next
    
            'Bind the datatable with the GridView
            GridView1.DataBind()
    
            myConnection.Close()
    End Sub
    How can i create dynamic hyperlinks for the date columns.....

    if you have any idea, how to do this, please help me. if you can some example, that's will be great.

    Thanks in advance.
  • aspdotnetuser
    New Member
    • Nov 2010
    • 22

    #2
    To create actions in gridview, you need to have templatefield. For dynamic templatefields you need to implement 'ITemplate' interface.

    I dont know whether URL reference is allowed in this forum. but still to help, hit "Dynamicall y Adding Template Columns to a GridView" in google search, you will land up in the right example i guess.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      It's not simple to add dynamic columns to a GridView.
      As @aspdotnetuser has suggested, you need to code a class that implements the ITemplate interface. The purpose of this class is to allow you to specify what controls are used as a template for the dynamic column that you wish to create. This is where you will specify that you want to use a LinkButton or HyperLink control for the data the column is bound to.

      Please remember that events are fired and if the parent doesn't handle the event then the event will be lost. So, if you are adding LinkButtons to dynamic column, remember that the click event for the LinkButton should be handled by the class that implements the ITemplate interface....if you want the page code to handle the event, then your ITemplate class has to re-raise the event for the parent to use.

      If you are simply using Hyperlinks, then there are no server-side events that will fire and things will be easier for you.

      To get you pointed in the right direction, I recommend that you familiarize yourself with how to use dynamic controls in ASP.NET, the INamingContaine r Interface and of course also the ITemplate Interface.

      Comment

      • remya1000
        New Member
        • Apr 2007
        • 115

        #4
        Thanks aspdotnetuser and Frinavale for your reply....

        i will try the templatefields and let you guys know about it... i'm not familiar with templatefields. ... let me give a try....

        created a small sample application of what i'm doing and i added that code here...

        just to make sure whether this is possible to create hyperlink dynamically for this...

        at run time only i will come to know how many columns i need to display. it depends up on the values from Database. so i'm creating columns dynamically and adding to gridview. till that it works fine. but i want some columns value to be hyperlink. so i need to create some columns hyperlink dynamically.


        Code:
        <%@ Page Language="VB" MasterPageFile="~/Master/Clearview.master" AutoEventWireup="false" CodeFile="SList.aspx.vb" Inherits="Issues" title="List - Home Page" %>
        
        
        <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
            <div style ="width:800px; overflow-x:scroll;">
             <asp:GridView ID="GridView1" runat="server" Width="800px" CellPadding="4" EnableTheming="True" ForeColor="#333333" GridLines="None" > 
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <RowStyle BackColor="#EFF3FB" />
                <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                 <EditRowStyle BackColor="#2461BF" />
                 <AlternatingRowStyle BackColor="White" />
            </asp:GridView>
           </div>
        </asp:Content>
        Code:
        Imports System
        Imports System.IO
        Imports System.Data
        Imports System.Data.SqlClient
        Imports System.Web.Configuration
        
        
        Partial Class Issues
            Inherits System.Web.UI.Page
        
            Dim aryDate, aryName, aryDate_Desc, aryDesc_Color_Date As New ArrayList
        
        
            Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                Dim Table_MAINPAGE As DataTable
                Dim Row As DataRow
                Dim dcol As DataColumn
                Dim myConnection As SqlConnection
                Dim MySQL As String
                Dim myCommand As SqlCommand
                Dim myreader As SqlDataReader
                Dim pFirst As Boolean = True
                Dim Name_NotExist, Group_NotExist As Boolean
        
                aryDate.Clear()
                aryName.Clear()
                aryDate_Desc.Clear()
                aryDesc_Color_Date.Clear()
        
                Table_MAINPAGE = New DataTable()
        
                dcol = New DataColumn(" # ")
                Table_MAINPAGE.Columns.Add(dcol)
        
                dcol = New DataColumn("Name")
                Table_MAINPAGE.Columns.Add(dcol)
        
                myConnection = New SqlConnection(WebConfigurationManager.ConnectionStrings("cvConnectionString").ToString)
                MySQL = "select DISTINCT ondate from sList ORDER BY ondate"
                myConnection.Open()
                myCommand = New SqlCommand(MySQL, myConnection)
                myreader = myCommand.ExecuteReader
                While myreader.Read
                    aryDate.Add(myreader(0))
                    dcol = New DataColumn(Trim(myreader(0)))
                    Table_MAINPAGE.Columns.Add(dcol)
                End While
                myreader.Close()
        
                pFirst = True
                MySQL = "Select fname, lname from Users ORDER BY fname"
                myCommand = New SqlCommand(MySQL, myConnection)
                myreader = myCommand.ExecuteReader
                While myreader.Read
                    If pFirst = True Then
                        pFirst = False
                        'Get distinct Name from database
                        aryName.Add(myreader(0) & " " & myreader(1))
                        GoTo NextValue
                    End If
        
                    Name_NotExist = False
                    Group_NotExist = False
                    For q As Integer = 0 To aryName.Count - 1
                        If myreader(0) & " " & myreader(1) <> aryName.Item(q) Then
                            Name_NotExist = True
                        Else
                            Name_NotExist = False
                            GoTo NextValue
                        End If
                    Next
                    If Name_NotExist = True Then
                        aryName.Add(myreader(0) & " " & myreader(1))
                    End If
        NextValue:
                End While
                myreader.Close()
        
        
                Dim h As Integer = 0
                Dim gBool As Boolean = False
                'Now add data for dynamic columns
                'As first column is increment, as number of data in database
                'Let's add some data to the other columns
                For k As Integer = 0 To aryName.Count - 1
                    If Trim(aryName.Item(k).split("-")(1)) = Trim(aryGroup.Item(p)) Then
                        aryDate_Desc.Clear()
                        MySQL = "select ondate, description, color from sList where [name] = '" & Trim(aryName.Item(k).ToString) & "' order by ondate"
                        myCommand = New SqlCommand(MySQL, myConnection)
                        myreader = myCommand.ExecuteReader
                        'Create a new row
                        Row = Table_MAINPAGE.NewRow()
                        h = h + 1
                        Row(" # ") = h
                        Row("Name") = aryName.Item(k).ToString
                        While myreader.Read
                            aryDate_Desc.Add(myreader(0) & " - " & myreader(1))
                            aryDesc_Color_Date.Add(myreader(0) & " -" & myreader(1) & " - " & myreader(3))
                        End While
                        For i As Integer = 0 To aryDate.Count - 1
                            gBool = False
                            For j As Integer = 0 To aryDate_Desc.Count - 1
                                If Trim(aryDate.Item(i)) = Trim(aryDate_Desc.Item(j).Split("-")(0)) Then
                                    'Initialize the row data.
                                    Row(Trim(aryDate.Item(i))) = Trim(aryDate_Desc.Item(j).Split("-")(1))
                                    gBool = True
                                    GoTo NextArrayValue
                                End If
                            Next
        NextArrayValue:
                            If gBool <> True Then
                                Row(Trim(aryDate.Item(i))) = "Add New"
                            End If
                        Next
                        'Add the row to the datatable.
                        Table_MAINPAGE.Rows.Add(Row)
                        myreader.Close()
                    End If
                Next
        
                'Initialize the DataSource
                GridView1.DataSource = Table_MAINPAGE
        
                For i As Integer = 0 To GridView1.Columns.Count - 1
                    GridView1.Columns(i).ItemStyle.Width = 500
                Next
        
                'Bind the datatable with the GridView
                GridView1.DataBind()
        
                myConnection.Close()
            End Sub
        
            Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
                Dim tCell As TableCell
                Dim drv As DataRowView
                Dim ob As Object
                Dim j As Integer = 1
        
                For i As Integer = 0 To aryDate.Count - 1
                    j = j + 1
                    If e.Row.RowType = DataControlRowType.DataRow Then
                        drv = e.Row.DataItem
                        ob = drv(aryDate.Item(i))
                        If ob.ToString.Contains("Work") Then
                            tCell = e.Row.Cells(j)
                            tCell.BackColor = Drawing.Color.Blue
                        ElseIf ob.ToString.Contains("Off") Then
                            tCell = e.Row.Cells(j)
                            tCell.BackColor = Drawing.Color.LightBlue
                        ElseIf ob.ToString.Contains("Out") Then
                            tCell = e.Row.Cells(j)
                            tCell.BackColor = Drawing.Color.Gray
                        ElseIf ob.ToString.Contains("Add New") Then
                            tCell = e.Row.Cells(j)
                            tCell.BackColor = Drawing.Color.White
                        End If
                    End If
                Next
            End Sub
        
            Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
                'If (e.Row.RowType = DataControlRowType.DataRow) Then
                '    Dim link As HyperLink = New HyperLink()
                '    link.Text = e.Row.DataItem
                '    link.NavigateUrl = "Update.aspx" + e.Row.DataItem
                '    ' link.NavigateUrl = "Navigate somewhere based on data: " + e.Row.DataItem
                '    e.Row.Cells(2).Controls.Add(link)
                'End If
            End Sub
        
        End Class
        my Database table looks like this

        Index-------Name--------------Date-----------------Description
        1------------John----------------12/1/2010---------- Work
        2------------Peter---------------12/2/2010---------- Out
        3------------John----------------12/3/2010---------- Off
        when this code runs, gridview display like this

        Index-----Name----------12/1/2010-----------12/2/2010------------12/3/2010
        1----------John-----------Work------------------ADD NEW------------Off
        2----------Peter----------ADD NEW-----------Out----------------------ADD NEW
        that's the way i want it to be displayed....

        but the next thing i want is to make all the Date coumns to displayed as hyperlink.


        for example :
        for Work (12/1/2010) - Update.aspx?id= 1
        for Off (12/3/2010) - Update.aspx?id= 3
        for Out (12/2/2010) - Update.aspx?id= 2
        How can i create dynamic hyperlinks for the date columns.....

        if you have any idea, how to do this, please please please help me. if you have some example, that's will be great.

        Thanks in advance.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Please read through the links I posted :)

          You will create a "template" to use for the column.
          This template will contain a HyperLink.
          The Hyperlink will be bound to the URL retrieved from the database.

          In order to create a dynamic template column you need to write a class that will be the dynamic template column. This class implements the ITemplate interface that we were talking about.

          When you retrieve the data from the database, you will dynamically create the number of columns that you need to use to display your data. When you create these columns, one of them will be your custom template column that contains the link that is bound to the data retrieved from the database.

          You have to create your columns in the Page Init event if you expect to be able to handle any events that are fired from controls within the dynamic columns.

          This event occurs every page request, it occurs before your page's ViewState is loaded (before the Page Load event) so you need to keep track of the number of columns to create using a cookie or a hidden field.


          -Frinny

          Comment

          • remya1000
            New Member
            • Apr 2007
            • 115

            #6
            Thanks Frinavale for your reply....

            i checked the TemplateField.. .

            when i try this code to display in DataTable Row, it's displaying this text inside textbox <a href=Update.asp x?id=81>" & "My Link Text" & "</a>
            Row("Date") = String.Format(" <a href=Update.asp x?id=81>" & "My Link Text" & "</a>")
            Then i tried this code using TemplateFiled,
            Code:
            Imports System.Web.UI
            Imports System.Web.UI.WebControls
            Imports system.IO
            
            
            Public Class TemplateHandler
                Implements ITemplate
            
                Private columnID, columnText As String
            
                Public Sub New(ByVal colText As String)
                    columnText = colText
                End Sub
            
                Private Sub ITemplate_InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
                    Dim lbl As New Label()
                    lbl.Text = columnText
                    container.Controls.Add(lbl)
                End Sub
            
            End Class
            Code:
            Imports System
            Imports System.IO
            Imports System.Data
            Imports System.Data.SqlClient
            Imports System.Web.Configuration
            
            
            Partial Class Issues
                Inherits System.Web.UI.Page
            
                Dim aryDate, aryName, aryDate_Desc, aryDesc_Color_Date As New ArrayList
            
            
                Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                    Dim Table_MAINPAGE As DataTable
                    Dim Row As DataRow
                    Dim dcol As DataColumn
                    Dim myConnection As SqlConnection
                    Dim MySQL As String
                    Dim myCommand As SqlCommand
                    Dim myreader As SqlDataReader
                    Dim pFirst As Boolean = True
                    Dim Name_NotExist, Group_NotExist As Boolean
            
                    aryDate.Clear()
                    aryName.Clear()
                    aryDate_Desc.Clear()
                    aryDesc_Color_Date.Clear()
            
                    Table_MAINPAGE = New DataTable()
            
                    dcol = New DataColumn(" # ")
                    Table_MAINPAGE.Columns.Add(dcol)
            
                    dcol = New DataColumn("Name")
                    Table_MAINPAGE.Columns.Add(dcol)
            
                    myConnection = New SqlConnection(WebConfigurationManager.ConnectionStrings("cvConnectionString").ToString)
                    MySQL = "select DISTINCT ondate from sList ORDER BY ondate"
                    myConnection.Open()
                    myCommand = New SqlCommand(MySQL, myConnection)
                    myreader = myCommand.ExecuteReader
                    While myreader.Read
                        aryDate.Add(myreader(0))
                    End While
                    myreader.Close()
            
                    pFirst = True
                    MySQL = "Select fname, lname from Users ORDER BY fname"
                    myCommand = New SqlCommand(MySQL, myConnection)
                    myreader = myCommand.ExecuteReader
                    While myreader.Read
                        If pFirst = True Then
                            pFirst = False
                            'Get distinct Name from database
                            aryName.Add(myreader(0) & " " & myreader(1))
                            GoTo NextValue
                        End If
            
                        Name_NotExist = False
                        Group_NotExist = False
                        For q As Integer = 0 To aryName.Count - 1
                            If myreader(0) & " " & myreader(1) <> aryName.Item(q) Then
                                Name_NotExist = True
                            Else
                                Name_NotExist = False
                                GoTo NextValue
                            End If
                        Next
                        If Name_NotExist = True Then
                            aryName.Add(myreader(0) & " " & myreader(1))
                        End If
            NextValue:
                    End While
                    myreader.Close()
            
            
                    Dim h As Integer = 0
                    Dim gBool As Boolean = False
                    'Now add data for dynamic columns
                    'As first column is increment, as number of data in database
                    'Let's add some data to the other columns
                    For k As Integer = 0 To aryName.Count - 1
                        If Trim(aryName.Item(k).split("-")(1)) = Trim(aryGroup.Item(p)) Then
                            aryDate_Desc.Clear()
                            MySQL = "select ondate, description, color from sList where [name] = '" & Trim(aryName.Item(k).ToString) & "' order by ondate"
                            myCommand = New SqlCommand(MySQL, myConnection)
                            myreader = myCommand.ExecuteReader
                            'Create a new row
                            Row = Table_MAINPAGE.NewRow()
                            h = h + 1
                            Row(" # ") = h
                            Row("Name") = aryName.Item(k).ToString
                            While myreader.Read
                                aryDate_Desc.Add(myreader(0) & " - " & myreader(1))
                                aryDesc_Color_Date.Add(myreader(0) & " -" & myreader(1) & " - " & myreader(3))
                            End While
                            'Add the row to the datatable.
                            Table_MAINPAGE.Rows.Add(Row)
                            myreader.Close()
                        End If
                    Next
            
                    GridView1.AutoGenerateColumns = False
            
                    Dim NameColumn As New BoundField()
                    NameColumn.DataField = " # "
                    NameColumn.HeaderText = " # "
                    GridView1.Columns.Add(NameColumn)
            
                    NameColumn = New BoundField()
                    NameColumn.DataField = "Name"
                    NameColumn.HeaderText = "Name"
                    GridView1.Columns.Add(NameColumn)
            
                    ' Here is template column portion
                    Dim TmpCol As New TemplateField()
                    TmpCol.HeaderText = aryDate.Item(0).ToString
                    GridView1.Columns.Add(TmpCol)
                    TmpCol.ItemTemplate = New TemplateHandler(String.Format("<a href=Update.aspx?id=" & "81" & ">" & "work" & "</a>"))
            
                    TmpCol = New TemplateField()
                    TmpCol.HeaderText = aryDate.Item(1).ToString
                    GridView1.Columns.Add(TmpCol)
                    TmpCol.ItemTemplate = New TemplateHandler(String.Format("<a href=Update.aspx?id=" & "81" & ">" & "Off" & "</a>"))
            
                    TmpCol = New TemplateField()
                    TmpCol.HeaderText = aryDate.Item(2).ToString
                    GridView1.Columns.Add(TmpCol)
                    TmpCol.ItemTemplate = New TemplateHandler(String.Format("<a href=Update.aspx?id=" & "81" & ">" & "Out" & "</a>"))
            
                    'Initialize the DataSource
                    GridView1.DataSource = Table_MAINPAGE
            
                    For i As Integer = 0 To GridView1.Columns.Count - 1
                        GridView1.Columns(i).ItemStyle.Width = 500
                    Next
            
                    'Bind the datatable with the GridView
                    GridView1.DataBind()
            
                    myConnection.Close()
                End Sub
            
                Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
                    Dim tCell As TableCell
                    Dim drv As DataRowView
                    Dim ob As Object
                    Dim j As Integer = 1
            
                    For i As Integer = 0 To aryDate.Count - 1
                        j = j + 1
                        If e.Row.RowType = DataControlRowType.DataRow Then
                            drv = e.Row.DataItem
                            ob = drv(aryDate.Item(i))
                            If ob.ToString.Contains("Work") Then
                                tCell = e.Row.Cells(j)
                                tCell.BackColor = Drawing.Color.Blue
                            ElseIf ob.ToString.Contains("Off") Then
                                tCell = e.Row.Cells(j)
                                tCell.BackColor = Drawing.Color.LightBlue
                            ElseIf ob.ToString.Contains("Out") Then
                                tCell = e.Row.Cells(j)
                                tCell.BackColor = Drawing.Color.Gray
                            ElseIf ob.ToString.Contains("Add New") Then
                                tCell = e.Row.Cells(j)
                                tCell.BackColor = Drawing.Color.White
                            End If
                        End If
                    Next
                End Sub
            
            End Class
            when i use the above code, its creating the hyperlink in label's inside gridview. but the gridview looks like this... its adds same text for the entire columns.
            Index-----Name----------12/1/2010-----------12/2/2010------------12/3/2010
            1----------John-----------Work-------------------Off----------------------Out
            2----------Peter----------Work-------------------Off----------------------Out
            But this is the format i need to display the gridview.
            Index-----Name----------12/1/2010-----------12/2/2010------------12/3/2010
            1----------John-----------Work------------------ADD NEW------------Off
            2----------Peter----------ADD NEW-----------Out----------------------ADD NEW
            is it possible to display it like that?

            i tried this code too.. but same result
            Code:
            Dim myLink As New HyperLink
            myLink.Text = columnText
            myLink.NavigateUrl = "Update.aspx?id=" & columnID
            container.Controls.Add(myLink)
            Code:
            Dim TmpCol As New TemplateField()
            TmpCol.HeaderText = aryDate.Item(0).ToString
            GridView1.Columns.Add(TmpCol)
            TmpCol.ItemTemplate = New TemplateHandler(81,"my Link Text")
            If you have any idea, how to do this, please let me know.

            Thanks in advance....

            Comment

            • remya1000
              New Member
              • Apr 2007
              • 115

              #7
              Thanks Gary for your reply and for the sample example.

              Sorry for this late reply... actually i was trying your codes and made some changes and it start displaying the fields in gridview. but hyperlink is not working correctly...

              The code used...
              Code:
                  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                     
                      Dim h As Integer = 0
                      Dim gBool As Boolean = False
                      'Now add data for dynamic columns
                      'As first column is increment, as number of data in database
                      'Let's add some data to the other columns
                      For k As Integer = 0 To aryName.Count - 1
                          If Trim(aryName.Item(k).split("-")(1)) = Trim(aryGroup.Item(p)) Then
                              aryDate_Desc.Clear()
                              MySQL = "select ondate, description, color, recno from sList where [name] = '" & Trim(aryName.Item(k).ToString) & "' order by ondate"
                              myCommand = New SqlCommand(MySQL, myConnection)
                              myreader = myCommand.ExecuteReader
                              'Create a new row
                              Row = Table_MAINPAGE.NewRow()
                              h = h + 1
                              Row(" # ") = h
                              Row("Name") = aryName.Item(k).ToString
                              While myreader.Read
                                  aryDate_Desc.Add(myreader(0) & " - " & myreader(1))
                                  aryDesc_Color_Date.Add(myreader(0) & " - " & myreader(1) & " - " & myreader(2))
                                  aryHyperLinkIndex.Add(myreader(0) & " - " & myreader(1) & " - " & myreader(3) & " - " & Trim(aryName.Item(k).ToString))
                              End While
              	For i As Integer = 0 To aryDate.Count - 1
                                  gBool = False
                                  For j As Integer = 0 To aryDate_Desc.Count - 1
                                      If Trim(aryDate.Item(i)) = Trim(aryDate_Desc.Item(j).Split("-")(0)) Then
                                          'Initialize the row data.
                                          Row(Trim(aryDate.Item(i))) = String.Format("<a href='Update.aspx?id=81'>" & Trim(aryDate_Desc.Item(j).Split(" - ")(1)) & "</a>") 
                                          gBool = True
                                          GoTo NextArrayValue
                                      End If
                                  Next
              NextArrayValue:
                                  If gBool <> True Then
                                      Row(Trim(aryDate.Item(i))) = "Add New"
              	        aryHyperLinkIndex.Add(Trim(aryDate.Item(i)) & " - " & "Add New" & " - " & "0" & " - " & Trim(aryName.Item(k).split("-")(0)).ToString)
                                  End If
                              Next
              
                              'Add the row to the datatable.
                              Table_MAINPAGE.Rows.Add(Row)
                              myreader.Close()
                          End If
                      Next
                          'Create a new row
                          Row = Table_MAINPAGE.NewRow()
                          Row(" # ") = ""
                          Row("Name") = ""
                          For i As Integer = 0 To aryDate.Count - 1
                              'Initialize the row data.
                              Row(Trim(aryDate.Item(i))) = ""
                          Next
                          'Add the row to the datatable.
                          Table_MAINPAGE.Rows.Add(Row)
                      Next
              
                      'Initialize the DataSource
                      GridView1.DataSource = Table_MAINPAGE
              
                      For i As Integer = 0 To GridView1.Columns.Count - 1
                          GridView1.Columns(i).ItemStyle.Width = 500
                      Next
              
                      'Bind the datatable with the GridView
                      GridView1.DataBind()
              
                      myConnection.Close()
                  End Sub
              
                  Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
                      Dim tCell As TableCell
                      Dim drv As DataRowView
                      Dim ob As Object
                      Dim j As Integer = 1
              
                      For i As Integer = 0 To aryDate.Count - 1
                          j = j + 1
                          If e.Row.RowType = DataControlRowType.DataRow Then
                              drv = e.Row.DataItem
                              ob = drv(aryDate.Item(i))
                              If ob.ToString.Contains("Work") Then
                                  tCell = e.Row.Cells(j)
                                  tCell.BackColor = Drawing.Color.Blue
                              ElseIf ob.ToString.Contains("Off") Then
                                  tCell = e.Row.Cells(j)
                                  tCell.BackColor = Drawing.Color.LightBlue
                              ElseIf ob.ToString.Contains("Out") Then
                                  tCell = e.Row.Cells(j)
                                  tCell.BackColor = Drawing.Color.Gray
                              ElseIf ob.ToString.Contains("Add New") Then
                                  tCell = e.Row.Cells(j)
                                  tCell.BackColor = Drawing.Color.White
                              End If
                          End If
                      Next
                  End Sub
              
              End Class
              
              Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
                           
                      If e.Row.RowType = DataControlRowType.DataRow Then
              
                          For i As Integer = 0 To aryDate.Count - 1
                              For k As Integer = 0 To aryHyperLinkIndex.Count - 1
                                  If Trim(aryDate.Item(i)) = Trim(aryHyperLinkIndex.Item(k).split("-")(0)) Then
                                      If Trim(e.Row.Cells(2).Text) = Trim(aryHyperLinkIndex.Item(k).Split("-")(1)) Then
                                          If Trim(e.Row.Cells(1).Text) = Trim(aryHyperLinkIndex.Item(k).split("-")(3)) Then
                                              e.Row.Cells(2).Text = e.Row.Cells(2).Text
                                              If Trim(e.Row.Cells(2).Text) = "Add New" Then
                                                  Dim link As HyperLink = New HyperLink()
                                                  link.Text = e.Row.Cells(2).Text
                                                  link.NavigateUrl = "AddValues.aspx?DateValue=" & Trim(aryDate.Item(i)) & "&NameValue=" & m(aryHyperLinkIndex.Item(k).split("-")(3))
                                                  e.Row.Cells(2).Controls.Add(link)
                                              Else
                                                  Dim link As HyperLink = New HyperLink()
                                                  link.Text = e.Row.Cells(2).Text
                                                  link.NavigateUrl = "ViewSchedule.aspx?ViewUpdateValue=" & Trim(aryHyperLinkIndex.Item(k).Split("-")(2))
                                                  e.Row.Cells(2).Controls.Add(link)
                                              End If
                                              Exit For
                                          End If
                                      End If
                                  End If
                              Next
                          Next
              
                         For i As Integer = 0 To aryDate.Count - 1
                                  For k As Integer = 0 To aryHyperLinkIndex.Count - 1
                                      If Trim(aryDate.Item(i)) = Trim(aryHyperLinkIndex.Item(k).split("-")(0)) Then
                                          If Trim(e.Row.Cells(3).Text) = Trim(aryHyperLinkIndex.Item(k).Split("-")(1)) Then
                                              If Trim(e.Row.Cells(1).Text) = Trim(aryHyperLinkIndex.Item(k).split("-")(3)) Then
                                                  e.Row.Cells(3).Text = e.Row.Cells(3).Text
                                                  If Trim(e.Row.Cells(3).Text) = "Add New" Then
                                                      Dim link As HyperLink = New HyperLink()
                                                      link.Text = e.Row.Cells(3).Text
                                                      link.NavigateUrl = "AddValues.aspx?DateValue=" & Trim(aryDate.Item(i)) & "&NameValue=" & Trim(aryHyperLinkIndex.Item(k).split("-")(3))
                                                      e.Row.Cells(3).Controls.Add(link)
                                                  Else
                                                      Dim link As HyperLink = New HyperLink()
                                                      link.Text = e.Row.Cells(3).Text
                                                      link.NavigateUrl = "ViewSchedule.aspx?ViewUpdateValue=" & Trim(aryHyperLinkIndex.Item(k).Split("-")(2))
                                                      e.Row.Cells(3).Controls.Add(link)
                                                  End If
                                                  Exit For
                                              End If
                                          End If
                                      End If
                                  Next
                         Next
              
                       End If
                      myWrite.Close()
                  End Sub
              for "Add New", when i try to hit the hyperlink, its taking all the "Add New" hyperlinks to a single index values. its not taking to corresponding index value.

              for example: First Add New - index 10
              Second Add New - index 12
              Third Add New - index 14

              while creating hyperlink its assigning correct index number to each hyperlink. but when i hit hyperlink, it always take index 14. always the last index is assigning to all the Add New's.

              is there anything wrong in this code? if you have any idea, why hyperlink is not getting the correct index, then can you please help me to figure this out...

              Thanks in advance...

              Comment

              • remya1000
                New Member
                • Apr 2007
                • 115

                #8
                Sorry.... that was a mistake i did while typing...

                Actually instead of this codes

                Row(Trim(aryDat e.Item(i))) = String.Format(" <a href='Update.as px?id=81'>" & Trim(aryDate_De sc.Item(j).Spli t(" - ")(1)) & "</a>")

                i'm using this

                Row(Trim(aryDat e.Item(i))) = Trim(aryDate_De sc.Item(j).Spli t("-")(1))
                while typing in this forum, i made that mistake...

                i will give some idea what i'm trying to so with this code...

                inside database the data is saved like this
                Index-------Name--------------Date-----------------Description
                1------------John----------------12/1/2010---------- Work
                2------------Peter---------------12/2/2010---------- Out
                3------------John----------------12/3/2010---------- Off
                and i want the above details to display like this in web page
                Index-----Name----------12/1/2010-----------12/2/2010------------12/3/2010
                1----------John-----------Work------------------ADD NEW------------Off
                2----------Peter----------ADD NEW-----------Out----------------------ADD NEW
                Code:
                Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                       
                        Dim h As Integer = 0
                        Dim gBool As Boolean = False
                        'Now add data for dynamic columns
                        For k As Integer = 0 To aryName.Count - 1
                            If Trim(aryName.Item(k).split("-")(1)) = Trim(aryGroup.Item(p)) Then
                                aryDate_Desc.Clear()
                	'for each name, need to get date, description, color and recno
                                MySQL = "select ondate, description, color, recno from sList where [name] = '" & Trim(aryName.Item(k).ToString) & "' order by ondate"
                                myCommand = New SqlCommand(MySQL, myConnection)
                                myreader = myCommand.ExecuteReader
                                'Create a new row
                                Row = Table_MAINPAGE.NewRow()
                	h = h + 1
                	'adding values to "#" row.
                                Row(" # ") = h
                	'adding values to "Name" row.
                                Row("Name") = aryName.Item(k).ToString
                                While myreader.Read
                                    aryDate_Desc.Add(myreader(0) & " - " & myreader(1))
                                    'adding date, description, index, name to an array. so while creating hyperlink, we can pass the index values		
                                    aryHyperLinkIndex.Add(myreader(0) & " - " & myreader(1) & " - " & myreader(3) & " - " & Trim(aryName.Item(k).ToString))
                                End While
                	For i As Integer = 0 To aryDate.Count - 1
                                    gBool = False
                                    For j As Integer = 0 To aryDate_Desc.Count - 1
                                        If Trim(aryDate.Item(i)) = Trim(aryDate_Desc.Item(j).Split("-")(0)) Then
                                            'adding value to "Date" row.
                                            Row(Trim(aryDate.Item(i))) = Trim(aryDate_Desc.Item(j).Split("-")(1))
                                            gBool = True
                                            GoTo NextArrayValue
                                        End If
                                    Next
                NextArrayValue:
                                    If gBool <> True Then
                                        'adding value as "Add New" to "Date" row, if no value is set.
                                        Row(Trim(aryDate.Item(i))) = "Add New"
                	        'adding date, description, index, name to an array. so while creating hyperlink, we can pass the index values
                	        aryHyperLinkIndex.Add(Trim(aryDate.Item(i)) & " - " & "Add New" & " - " & "0" & " - " & Trim(aryName.Item(k).split("-")(0)).ToString)
                                    End If
                                Next
                
                                'Add the row to the datatable.
                                Table_MAINPAGE.Rows.Add(Row)
                                myreader.Close()
                            End If
                        Next
                            'for new group, we need to create empty row (empty row will seperate each group)
                            'Create a new row
                            Row = Table_MAINPAGE.NewRow()
                            Row(" # ") = ""
                            Row("Name") = ""
                            For i As Integer = 0 To aryDate.Count - 1
                                'Initialize the row data.
                                Row(Trim(aryDate.Item(i))) = ""
                            Next
                            'Add the row to the datatable.
                            Table_MAINPAGE.Rows.Add(Row)
                        Next
                
                        'Initialize the DataSource
                        GridView1.DataSource = Table_MAINPAGE
                
                        For i As Integer = 0 To GridView1.Columns.Count - 1
                            GridView1.Columns(i).ItemStyle.Width = 500
                        Next
                
                        'Bind the datatable with the GridView
                        GridView1.DataBind()
                
                        myConnection.Close()
                    End Sub
                
                Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
                             
                        If e.Row.RowType = DataControlRowType.DataRow Then
                
                            'checking each Date	
                            For i As Integer = 0 To aryDate.Count - 1
                                For k As Integer = 0 To aryHyperLinkIndex.Count - 1
                	    'if Date and aryHyperLinkIndex are equal
                                    If Trim(aryDate.Item(i)) = Trim(aryHyperLinkIndex.Item(k).split("-")(0)) Then
                	        'if current cell2  (first Date) text is equal to aryHyperLinkIndex description 	
                                        If Trim(e.Row.Cells(2).Text) = Trim(aryHyperLinkIndex.Item(k).Split("-")(1)) Then
                	            'if current cell1 (Name) text is equal to aryHyperLinkIndex name	
                                            If Trim(e.Row.Cells(1).Text) = Trim(aryHyperLinkIndex.Item(k).split("-")(3)) Then
                                                e.Row.Cells(2).Text = e.Row.Cells(2).Text
                   		'if current cell2 (first date) text is equal to "Add New", then create Hyperlink
                                                If Trim(e.Row.Cells(2).Text) = "Add New" Then
                                                    Dim link As HyperLink = New HyperLink()
                                                    link.Text = e.Row.Cells(2).Text
                		    'Passing the date and name
                                                    link.NavigateUrl = "AddValues.aspx?DateValue=" & Trim(aryDate.Item(i)) & "&NameValue=" & m(aryHyperLinkIndex.Item(k).split("-")(3))
                                                    e.Row.Cells(2).Controls.Add(link)
                                                Else
                                                    Dim link As HyperLink = New HyperLink()
                                                    link.Text = e.Row.Cells(2).Text
                		    'Passing the index
                                                    link.NavigateUrl = "ViewUpdate.aspx?ViewUpdateValue=" & Trim(aryHyperLinkIndex.Item(k).Split("-")(2))
                                                    e.Row.Cells(2).Controls.Add(link)
                                                End If
                                                Exit For
                                            End If
                                        End If
                                    End If
                                Next
                            Next
                
                           'checking each Date	
                           For i As Integer = 0 To aryDate.Count - 1
                                    For k As Integer = 0 To aryHyperLinkIndex.Count - 1
                 	        'if Date and aryHyperLinkIndex are equal
                                        If Trim(aryDate.Item(i)) = Trim(aryHyperLinkIndex.Item(k).split("-")(0)) Then
                	           'if current cell2  (first Date) text is equal to aryHyperLinkIndex description 
                                            If Trim(e.Row.Cells(3).Text) = Trim(aryHyperLinkIndex.Item(k).Split("-")(1)) Then
                                                'if current cell1 (Name) text is equal to aryHyperLinkIndex name	
                                                If Trim(e.Row.Cells(1).Text) = Trim(aryHyperLinkIndex.Item(k).split("-")(3)) Then
                                                    e.Row.Cells(3).Text = e.Row.Cells(3).Text
                   		    'if current cell2 (first date) text is equal to "Add New", then create Hyperlink
                                                    If Trim(e.Row.Cells(3).Text) = "Add New" Then
                                                        Dim link As HyperLink = New HyperLink()
                                                        link.Text = e.Row.Cells(3).Text
                                                        'Passing the date and name
                                                        link.NavigateUrl = "AddValues.aspx?DateValue=" & Trim(aryDate.Item(i)) & "&NameValue=" & Trim(aryHyperLinkIndex.Item(k).split("-")(3))
                                                        e.Row.Cells(3).Controls.Add(link)
                                                    Else
                                                        Dim link As HyperLink = New HyperLink()
                                                        link.Text = e.Row.Cells(3).Text
                                                        'Passing the index
                                                        link.NavigateUrl = "ViewUpdate.aspx?ViewUpdateValue=" & Trim(aryHyperLinkIndex.Item(k).Split("-")(2))
                                                        e.Row.Cells(3).Controls.Add(link)
                                                    End If
                                                    Exit For
                                                End If
                                            End If
                                        End If
                                    Next
                           Next
                
                         End If
                    End Sub
                GridView1_RowDa taBound

                aryHyperLinkInd ex contain - date, description, index, name of all items in each row.

                if Date and aryHyperLinkInd ex are equal
                if current cell2 (first Date) text is equal to aryHyperLinkInd ex description
                if current cell1 (Name) text is equal to aryHyperLinkInd ex name
                if current cell2 (first date) text is equal to "Add New"
                then create Hyperlink for Add New and Passing the date and name
                else
                create HyperLink for Text and Passing the index
                for HyperLink Text, its taking the correct index and it works fine.
                But for Add New HyperlLink, i'm passing date and name. its getting the correct name. but date is set to the last date.

                i check the view source and for Add New, its taking the last Date for all.
                <td>1</td><td>John </td><td style="backgrou nd-color:DarkOrang e;"><a href="ViewUpdat e.aspx?ViewUpda teValue=102">Wo rk</a></td><td style="backgrou nd-color:White;">< a href="AddValues .aspx?DateValue =1/10/2011&amp;NameVa lue=John">Add New</a></td><td style="backgrou nd-color:White;">< a href="AddValues .aspx?DateValue =1/10/2011&amp;NameVa lue=John">Add New</a></td><td style="backgrou nd-color:White;">< a href="AddValues .aspx?DateValue =1/10/2011&amp;NameVa lue=John">Add New</a></td><td style="backgrou nd-color:White;">< a href="AddValues .aspx?DateValue =1/10/2011&amp;NameVa lue=John">Add New</a></td><td style="backgrou nd-color:White;">< a href="AddValues .aspx?DateValue =1/10/2011&amp;NameVa lue=John">Add New</a></td><td style="backgrou nd-color:White;">< a href="AddValues .aspx?DateValue =1/10/2011&amp;NameVa lue=John">Add New</a></td>

                <td>2</td><td>Peter </td><td style="backgrou nd-color:White;">< a href="AddValues .aspx?DateValue =1/10/2011&amp;NameVa lue=Peter">Add New</a></td><td style="backgrou nd-color:OliveDrab ;"><a href="ViewUpdat e.aspx?ViewUpda teValue=103">Of f</a></td><td style="backgrou nd-color:White;">< a href="AddValues .aspx?DateValue =1/10/2011&amp;NameVa lue=Peter">Add New</a></td><td style="backgrou nd-color:White;">< a href="AddValues .aspx?DateValue =1/10/2011&amp;NameVa lue=Peter">Add New</a></td><td style="backgrou nd-color:White;">< a href="AddValues .aspx?DateValue =1/10/2011&amp;NameVa lue=Peter">Add New</a></td><td style="backgrou nd-color:White;">< a href="AddValues .aspx?DateValue =1/10/2011&amp;NameVa lue=Peter">Add New</a></td><td style="backgrou nd-color:White;">< a href="AddValues .aspx?DateValue =1/10/2011&amp;NameVa lue=Peter">Add New</a></td>
                is there anything wrong in this code? if you have any idea, why hyperlink is not getting the correct date, then can you please help me to figure this out...

                Thanks in advance...

                Comment

                • remya1000
                  New Member
                  • Apr 2007
                  • 115

                  #9
                  Thank you so much for your help to solve this problem...

                  adding code here. so later if someone have this problem, they can check this.
                  Code:
                  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                         
                          Dim h As Integer = 0
                          Dim gBool As Boolean = False
                          'Now add data for dynamic columns
                          For k As Integer = 0 To aryName.Count - 1
                              If Trim(aryName.Item(k).split("-")(1)) = Trim(aryGroup.Item(p)) Then
                                  aryDate_Desc.Clear()
                  	'for each name, need to get date, description, color and recno
                                  MySQL = "select ondate, description, color, recno from sList where [name] = '" & Trim(aryName.Item(k).ToString) & "' order by ondate"
                                  myCommand = New SqlCommand(MySQL, myConnection)
                                  myreader = myCommand.ExecuteReader
                                  'Create a new row
                                  Row = Table_MAINPAGE.NewRow()
                  	h = h + 1
                  	'adding values to "#" row.
                                  Row(" # ") = h
                  	'adding values to "Name" row.
                                  Row("Name") = aryName.Item(k).ToString
                                  While myreader.Read
                                      aryDate_Desc.Add(myreader(0) & " - " & myreader(1))
                                      'adding date, description, index, name to an array. so while creating hyperlink, we can pass the index values		
                                      aryHyperLinkIndex.Add(myreader(0) & " - " & myreader(1) & " - " & myreader(3) & " - " & Trim(aryName.Item(k).ToString))
                                  End While
                  	For i As Integer = 0 To aryDate.Count - 1
                                      gBool = False
                                      For j As Integer = 0 To aryDate_Desc.Count - 1
                                          If Trim(aryDate.Item(i)) = Trim(aryDate_Desc.Item(j).Split("-")(0)) Then
                                              'adding value to "Date" row.
                                              Row(Trim(aryDate.Item(i))) = Trim(aryDate_Desc.Item(j).Split("-")(1))
                                              gBool = True
                                              GoTo NextArrayValue
                                          End If
                                      Next
                  NextArrayValue:
                                      If gBool <> True Then
                                          'adding value as "Add New" to "Date" row, if no value is set.
                                          Row(Trim(aryDate.Item(i))) = "Add New"
                  	        'adding date, description, index, name to an array. so while creating hyperlink, we can pass the index values
                  	        aryHyperLinkIndex.Add(Trim(aryDate.Item(i)) & " - " & "Add New" & " - " & "0" & " - " & Trim(aryName.Item(k).split("-")(0)).ToString)
                                      End If
                                  Next
                  
                                  'Add the row to the datatable.
                                  Table_MAINPAGE.Rows.Add(Row)
                                  myreader.Close()
                              End If
                          Next
                              'for new group, we need to create empty row (empty row will seperate each group)
                              'Create a new row
                              Row = Table_MAINPAGE.NewRow()
                              Row(" # ") = ""
                              Row("Name") = ""
                              For i As Integer = 0 To aryDate.Count - 1
                                  'Initialize the row data.
                                  Row(Trim(aryDate.Item(i))) = ""
                              Next
                              'Add the row to the datatable.
                              Table_MAINPAGE.Rows.Add(Row)
                          Next
                  
                          'Initialize the DataSource
                          GridView1.DataSource = Table_MAINPAGE
                  
                          For i As Integer = 0 To GridView1.Columns.Count - 1
                              GridView1.Columns(i).ItemStyle.Width = 500
                          Next
                  
                          'Bind the datatable with the GridView
                          GridView1.DataBind()
                  
                          myConnection.Close()
                      End Sub
                  
                  
                  Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
                       
                    If e.Row.RowType = DataControlRowType.DataRow Then
                  
                               'gets first date cell's header	
                              Dim Header_Date1 As DataControlFieldHeaderCell = CType(Me.GridView1.HeaderRow.Cells(2), DataControlFieldHeaderCell)
                                  For k As Integer = 0 To aryHyperLinkIndex.Count - 1
                                       'checks if first date cell's header and AryHyperLinkIndex date are equal
                                      If Trim(Header_Date1.Text) = Trim(aryHyperLinkIndex.Item(k).split("-")(0)) Then
                                          'if Current cell2  (first Date) text is equal to aryHyperLinkIndex description 	
                                          If Trim(e.Row.Cells(2).Text) = Trim(aryHyperLinkIndex.Item(k).Split("-")(1)) Then
                                              'if current cell1 (Name) text is equal to aryHyperLinkIndex name
                                              If Trim(e.Row.Cells(1).Text) = Trim(aryHyperLinkIndex.Item(k).split("-")(3)) Then
                                                  e.Row.Cells(2).Text = e.Row.Cells(2).Text
                                                  'if current cell2 (first date) text is equal to "Add New", then create Hyperlink
                                                  If Trim(e.Row.Cells(2).Text) = "Add New" Then
                                                      Dim link As HyperLink = New HyperLink()
                                                      link.Text = e.Row.Cells(2).Text
                                                      'Passing the date and name
                                                      link.NavigateUrl = "AddValues.aspx?DateValue=" & Trim(Header_Date1.Text) & "&NameValue=" & Trim(aryHyperLinkIndex.Item(k).split("-")(3))
                                                      e.Row.Cells(2).Controls.Add(link)
                                                      GoTo SecondCell
                                                  Else
                                                      Dim link As HyperLink = New HyperLink()
                                                      link.Text = e.Row.Cells(2).Text
                                                      'Passing index
                                                      link.NavigateUrl = "ViewUpdates.aspx?ViewUpdateValue=" & Trim(aryHyperLinkIndex.Item(k).Split("-")(2))
                                                      e.Row.Cells(2).Controls.Add(link)
                                                      GoTo SecondCell
                                                  End If
                                              End If
                                          End If
                                      End If
                                  Next
                  SecondCell:
                  
                          End If
                      End Sub

                  Comment

                  Working...