Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: (untagged)
Hi,

I have defined a hyperlink in a gridview but the problem is i want extract the value of that hyperlink in a textbox.since i am trying it i am getting a null value.Hyperlink is the 1st column in the gridview and also i am using the update panel.

Please any body can solve it..

Thanks in advance.
Posted

1 solution

Hi,

I think you were not cleared about when you want value of Hyperlink...So i assumed it will either on gridview row data bound or Button click. 

Protected Sub gvList_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvList.RowDataBound
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            'Now you can get Hyperlink control with name ('HyperLink1') for current row, assumed it is on zero position (1st column of gridview)
            Dim hlnk As HyperLink = CType(e.Row.FindControl("HyperLink1"), HyperLink)
            Response.Write("<script>alert('Text: '" & hlnk.Text & "<br/>URL: " & hlnk.NavigateUrl & "');</script>")
        End If
    End Sub

    Protected Sub btnGetValue_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        For r As Integer = 0 To gvList.Rows.Count
            'Now you can get Hyperlink control with name ('HyperLink1') for all row, assumed it is on zero position (1st column of gridview)
            Dim hlnk As HyperLink = CType(gvList.Rows(r).FindControl("HyperLink1"), HyperLink)
            Response.Write("<script>alert('Text: '" & hlnk.Text & "<br/>URL: " & hlnk.NavigateUrl & "');</script>")
        Next
    End Sub

 

I think this would be helpful :).

Thanks & Regards,
Imdad

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900