This is a migrated thread and some comments may be shown as answers.

Getting cell value from GridHyperLinkColumn

3 Answers 333 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 1
Jim asked on 14 Feb 2012, 07:29 PM
Hello,
I inherited a project and I'm trying to get the value of the cells within a GridHyperLinkColumn.
The existing code is as follows:

 

 

Protected Sub gvLaneDBStatus_ItemDatabound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles gvLaneDBStatus.ItemDataBound

     If TypeOf e.Item Is GridDataItem Then

       Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem)

        Dim hl As GridHyperLinkColumn = CType(gvLaneDBStatus.MasterTableView.Columns.FindByUniqueName("LnStatus"), GridHyperLinkColumn)

 

            hl.ImageUrl = "../../images/" + CStr(hl.DataTextField) + ".gif"

  

 

    End If

 

End Sub

 


The DataTextField property is returning the data field specified in the properties, as it should.  I need the actual cell values which will in turn display a corresponding graphic in the cell.

Thanks very much,
Jim

3 Answers, 1 is accepted

Sort by
0
Jim
Top achievements
Rank 1
answered on 14 Feb 2012, 09:14 PM
Update:

I was working with the code a bit and currently have the following but still have a problem...

        Protected Sub gvLaneDBStatus_ItemDatabound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles gvLaneDBStatus.ItemDataBound

            If TypeOf e.Item Is GridDataItem Then

                Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem)

                Dim hl As GridHyperLinkColumn = CType(gvLaneDBStatus.MasterTableView.Columns.FindByUniqueName("LnStatus"), GridHyperLinkColumn)
                Dim link As HyperLink = DirectCast(dataItem("LnStatus").Controls(0), HyperLink)
                hl.ImageUrl = "../../images/" + link.Text + ".gif"
                'hl.ImageUrl = "../../images/" + CStr(hl.DataTextField) + ".gif"

            End If

        End Sub


The problem is that the images are displaying one row "off".  In other words the first row should be a red dot graphic but displays the hyperlink word "Red".  The second row should be a green dot graphic but displays the red dot graphic that should be in the previous row.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 15 Feb 2012, 07:14 AM
Hello,

I am not quite sure about your requirement. Try the following code to access the GridHyperLinkColumn.
VB:
Protected Sub gvLaneDBStatus_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim link As HyperLink = DirectCast(item("LnStatus").Controls(0), HyperLink)
        link.ImageUrl = "imageurl"
    End If
End Sub

-Shinu.
0
Jim
Top achievements
Rank 1
answered on 15 Feb 2012, 02:06 PM
That did the trick.  Thank you very much.
Tags
Grid
Asked by
Jim
Top achievements
Rank 1
Answers by
Jim
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or