Solved

Change hyperlinkfield in gridview in ASP.net **specifically VB**

Posted on 2011-03-23
3
852 Views
Last Modified: 2012-06-27
I need the VB version of this.  What I want to do is take the value of one cell in a gridview row and add that value to a hyperlinkfield.

For each row in this gridview, I want to do this to the first cell:

hyperlinkfield = "http://myaddress/"+ ValueOfCell5

I see how to do this in C# (example below), I have been unable to get a version of it to work in ASP.NET VB


protected void gridCaseMember_RowDataBound(object sender, GridViewRowEventArgs e){

 if (e.Row.RowType == DataControlRowType.DataRow){
 HyperLink myLink = (HyperLink)e.Row.Cells[0].Controls[0];
 
myLink.NavigateUrl = “http://www.bing.com”;    }
 
}

Open in new window

0
Comment
Question by:Zipbang
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Rick earned 500 total points
ID: 35202891
Try This:
If e.Row.RowType = DataControlRowType.DataRow Then

  Dim lnk As New HyperLink

  With lnk
    .NavigateUrl = "http://myaddress/" & e.Row.Cells(5).Text
    .Text = e.Row.Cells(5).Text
  End With

  With e.Row.Cells(0)
    .Text = ""
    .Controls.Add(lnk)
  End With

End If

Open in new window

0
 
LVL 13

Expert Comment

by:Rick
ID: 35202922
And if you already had a Hyperlink in cell 0:

If e.Row.RowType = DataControlRowType.DataRow Then

DirectCast(e.Row.Cells(0).FindControl("YourHyperLink"), Hyperlink).Text = DirectCast(e.Row..Cells(5).Text

DirectCast(e.Row.Cells(0).FindControl("YourHyperLink"), Hyperlink).NavigateUrl = "http://myaddress/" & e.Row.Cells(5).Text

End If
0
 

Author Closing Comment

by:Zipbang
ID: 35206063
This is perfect!  Great answer and couldn't have been any quicker.

Thanks!!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question