473,379 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to UrlEncode a hyperlink in a GridView?

I got into trouble with this problem.

The data I am presenting in a GridView control has a column called
"Website". That data comes from a stored procedure in SQL Server
2000. Most of them have valid http urls. But some of them say
"None" or "Not available".

In the GridView, I would like create a hyperlink for those valid http
urls only, and simply plain-output those which say "None" or "Not
available".

I tried the HyperLinkField of Gridview, but I don't think we can
conditionally turn off a hyperlink through this field, correct?

So, instead, I managed to create hyperlinks for those valid http urls
in the stored procedure by doing this:

CASE WHEN CHARINDEX('http', Website) THEN
'<a href="'+ Website + ' ">' + Website + '</a>'
ELSE
Website
END AS Website

The output looks perfect in SQL Sever Management Studio.

In the GridView, I simply bind this Website field to a BoundField.
But, GridView does not render the hyper link for me, instead it simply
output the hyperlink at a HTML text like so:

<a href="http://www.google.com">http://www.google.com</a>

How can I let GridView render the hyperlink for me? I was trying to
do this:

<asp:BoundField HeaderText="Website" DataField='<%
Server.UrlEncode("Website") %>' />

But it isn't successful.

Any idea? Thanks.
Aug 6 '08 #1
1 3023
On Aug 6, 11:49*am, Author <gnewsgr...@gmail.comwrote:
I got into trouble with this problem.

The data I am presenting in a GridView control has a column called
"Website". *That data comes from a stored procedure in SQL Server
2000. *Most of them have *valid http urls. *But some of them say
"None" or "Not available".

In the GridView, I would like create a hyperlink for those valid http
urls only, and simply plain-output those which say "None" or "Not
available".

I tried the HyperLinkField of Gridview, but I don't think we can
conditionally turn off a hyperlink through this field, correct?

So, instead, I managed to create hyperlinks for those valid http urls
in the stored procedure by doing this:

CASE WHEN CHARINDEX('http', Website) THEN
* * *'<a href="'+ Website + ' ">' + Website + '</a>'
ELSE
* * *Website
END AS Website

The output looks perfect in SQL Sever Management Studio.

In the GridView, I simply bind this Website field to a BoundField.
But, GridView does not render the hyper link for me, instead it simply
output the hyperlink at a HTML text like so:

<a href="http://www.google.com">http://www.google.com</a>

How can I let GridView render the hyperlink for me? *I was trying to
do this:

<asp:BoundField HeaderText="Website" DataField='<%
Server.UrlEncode("Website") %>' />

But it isn't successful.

Any idea? *Thanks.
I just recall that there is a property called HtmlEncode of
BoundField. Set it to false, and it works. Thanks for reading anyway.
Aug 6 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Fawke101 | last post by:
Hi there, I am having trouble with some data that is ripped from a SQL database and displayed as a hyperlink. The hyperlink inserts the data into a querystring so the next page can read it. ...
3
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I...
3
by: Wayne Wengert | last post by:
I am trying to impliment the extensions to the Club Starter kit as described at: http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/extendclubwebsitesk.asp but when I...
1
by: Carlos | last post by:
Hi all, I need a field that it is both databound, and hyperlink in a gridview. That is, the value is obtained from a query, and at the same time needs to point to a new page where will be used...
1
by: willip | last post by:
I have a Gridview control with a Databound Hyperlink. e.g.: <asp:HyperLinkField HeaderText="MyTitle" DataNavigateUrlFields="MyID" DataNavigateUrlFormatString="~/ShowMe.aspx?MyID={0}"...
3
by: William LaMartin | last post by:
I have a gridview (with no properties set) on an aspx page which I populate from an XML file with the code below. The data in the XML file looks like this <description>National Trust for...
7
by: David | last post by:
Using ASP.Net 2.0 and VS 2005. I have a search page that has server controls, (textboxes, dropdownlists, etc.) that are used for searching and returning data in a GridView. One of the GridView...
4
by: =?Utf-8?B?QW1pciBUb2hpZGk=?= | last post by:
Hi I have a GridView that is displaying master records. Some of these records have child records. I would like to a column to my master GridView such that for each master record that has...
1
by: Paul W Smith | last post by:
The text below is a GridView I am trying to use to display some data from a database. I am using one templatefield of grid because I want the contents of the record fields to appear on three...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.