?
Solved

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

Posted on 2011-03-23
3
Medium Priority
?
858 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Rick earned 2000 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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