Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-23
3
Medium Priority
?
860 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

636 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