Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7591241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:36:12+00:00 2026-05-30T20:36:12+00:00

I have an ASP.NET Web Forms application. In my application I have a GridView

  • 0

I have an ASP.NET Web Forms application. In my application I have a GridView that works smoothly. I have several text fields and the last one is a <asp:hyperlinkfield>.

Now I would like to programmatically change the field by placing a simple link instead of the hyperlinkfield if a specific condition is fulfilled. Therefore I catch the onRowDataBound event:

Sub myGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles myGridView.RowDataBound

    If (condition) Then
           Dim link = New HyperLink()
           link.Text = "login"
           link.NavigateUrl = "login.aspx"
           e.Row.Cells(3).Controls.Add(link)
        End If
    End If
End Sub

where n is the cell where the hyperlinkfield is placed. With this code it just adds to the hyperlinkfield the new link. How can I replace it?

PS: The code is in VB6 but I am a C# programmer, answers with both languages are accepted

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:36:13+00:00Added an answer on May 30, 2026 at 8:36 pm

    Remove the control you want to replace from the collection before adding the new one:

    protected void TestGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
        HyperLink newHyperLink = new HyperLink();
        newHyperLink.Text = "New";
        e.Row.Cells[3].Controls.RemoveAt(0);
        e.Row.Cells[3].Controls.Add(newHyperLink);
      }
    }
    

    But I agree with the others, just change the existing link’s properties:

    protected void TestGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
        HyperLink link = e.Row.Cells[0].Controls[0] as HyperLink;
        if (link != null)
        {
          link.Text = "New";
          link.NavigateUrl = "New";
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET web application that is using forms authentication. Everything is configured
Using web forms I know that you can only have one ASP.NET form on
I have a ASP.NET Web Forms application that internally makes many SOAP and REST
I have developed a web application (ASP.NET Web Forms). One of my customer has
I have an ASP.NET web forms application that requires that requires that a user
I have an ASP.NET web application that uses jQuery on client side. On one
We have an ASP.NET web forms application that is probably vulnerable to Cross-site request
I have an asp.net Web Forms application that needs to send emails. I like
I have an ASP .NET Web Forms application that makes use of the 'WebMethod'
My team and I have a asp.net web forms application and are using several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.