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 7074169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:01:08+00:00 2026-05-28T06:01:08+00:00

I want to process a field retrieved from the database for a Gridview to

  • 0

I want to process a field retrieved from the database for a Gridview to check to see if the information in it is a hyperlink. If it is, I want to generate a link from it, otherwise just leave it as raw text. At the moment the field in the Gridview looks like:

    <asp:TemplateField HeaderText="Reference">
        <EditItemTemplate>
            <asp:TextBox ID="txtReference" runat="server" Text='<%# Bind("Reference") %>'></asp:TextBox>
        </EditItemTemplate>
        <ItemTemplate>
            <asp:Label ID="Label3" runat="server" Text='<%# Bind("Reference") %>'></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>

I tried modifying what’s in the ‘Text’ attribute of the ItemTemplate but no matter what I put in I get errors on pageload. How can I dynamically modify what’s sent to the browser based on the specific info bound in this field?

Thanks a lot!

  • 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-28T06:01:08+00:00Added an answer on May 28, 2026 at 6:01 am

    I fixed this by using both a Label and a HyperLink in my TemplateField, showing the HyperLink (and hiding the Label) if the bound text qualifies as a proper URL.

    The following ASP.NET sets up the potential HTML to output:

    ASP.NET

    <asp:TemplateField HeaderText="Reference"> 
        <ItemTemplate>
                    <asp:Label ID="lblReference" runat="server" Visible='<%# !isTextHyperlink(Eval("Reference")) %>' Text='<%# Bind("Reference") %>'/>
                    <asp:HyperLink ID="hlReference" runat="server" Visible='<%# isTextHyperlink(Eval("Reference")) %>' Text='<%# Bind("Reference") %>' NavigateUrl='<%# Bind("Reference") %>'/>
        </ItemTemplate> 
    </asp:TemplateField> 
    

    I added a function in the pages ‘codebehind’ like this:

    C#

    protected bool isTextHyperlink(object refobj)
    {
        string refstring = refobj.ToString();
        try
        {
            Uri uri = new Uri(refstring);
            return Uri.CheckSchemeName(uri.Scheme);
        }
        catch
        {
            // not a valid uri (that Uri can construct with)
            return false;
        }
    }
    

    Many thanks to Brissles for the suggestion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check during edit form saving process the value of a field
I want to process each source code file after it has been preprocessed: myprocess
I want to process every element of a for-loop. Taking this code, why is
I want to process a medium to large number of text snippets using a
I have the following XML and I want to process it so that I
I have a c++ process, I want that process should always remain on foreground,
Say I have a data file that I want to process; I want to
I have some data generated in MATLAB that I want to process using Perl.
I have a set of .csv files that I want to process. It would
I have around 5 GB of html data which I want to process to

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.