Solved

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

Posted on 2011-03-23
3
854 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Date on a table 16 35
Adding where clause to entity statement c# 1 48
ASP.NET data base connection 35 40
Validation for a field in asp.net 3 14
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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