473,398 Members | 2,393 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,398 software developers and data experts.

Help: Working with hyperlinks in C#

Say I want to pull a bunch of records from a contacts database into a
gridview and one of the fields contains an email address. Now suppose
I want to make that email address clickable by putting it in a string
(strEmail) and wrapping it in a hyperlink like this ASP Classic
example...
"<a href='mailto:" & strEmail & "'>" & strEmail & "</a>"

How do I pull that off in a gridview? Step by step or tutorial link
would be great if available.

I am using VS 2005, ASP.Net 2.0 with C# code behind.

Thanks for your help in advance,

Bill

Jan 30 '07 #1
4 3041
Do you already know how to populate a GridView without the hyperlink?

Jan 30 '07 #2

You can use the concept here
http://www.gridviewguy.com/ArticleDe...?articleID=166

and just use a different type of function
protected string FormatEmailHref(string email)
{

if(email.length>0)

{

return "<href mailto:'" + email + "'>" + email + "</a>";

}

return "n/a";

}

something like that.

Bookmark that sight for GRIDVIEW stuff.


"Bill" <bi*************@yahoo.comwrote in message
news:11*********************@m58g2000cwm.googlegro ups.com...
Say I want to pull a bunch of records from a contacts database into a
gridview and one of the fields contains an email address. Now suppose
I want to make that email address clickable by putting it in a string
(strEmail) and wrapping it in a hyperlink like this ASP Classic
example...
"<a href='mailto:" & strEmail & "'>" & strEmail & "</a>"

How do I pull that off in a gridview? Step by step or tutorial link
would be great if available.

I am using VS 2005, ASP.Net 2.0 with C# code behind.

Thanks for your help in advance,

Bill

Jan 30 '07 #3
you could also use a template field and put your <a href...in that.
currently thats what I am doing and passing params to the page in the link
and works well.

"Bill" <bi*************@yahoo.comwrote in message
news:11*********************@m58g2000cwm.googlegro ups.com...
Say I want to pull a bunch of records from a contacts database into a
gridview and one of the fields contains an email address. Now suppose
I want to make that email address clickable by putting it in a string
(strEmail) and wrapping it in a hyperlink like this ASP Classic
example...
"<a href='mailto:" & strEmail & "'>" & strEmail & "</a>"

How do I pull that off in a gridview? Step by step or tutorial link
would be great if available.

I am using VS 2005, ASP.Net 2.0 with C# code behind.

Thanks for your help in advance,

Bill

Jan 30 '07 #4
Sure, example that should show you how to accomplish this task:

-- begin code --

<asp:GridView runat="server" ID="gridView" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>No.</HeaderTemplate>
<ItemTemplate>
<%# Container.DataItemIndex.ToString() %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Name" DataField="Name"/>
<asp:BoundField HeaderText="Email" DataField="Email"
DataFormatString="<a href='mailto:{0}'>{0}</a>"/>
</Columns>
</asp:GridView>

<script runat="server">

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gridView.DataSource = GetExampleData(10);
gridView.DataBind();
}
}

/// <summary>
///
/// </summary>
/// <returns></returns>
private DataTable GetExampleData(int rowCount)
{
DataTable table = new DataTable();
DataRow row = null;

table.Columns.Add("Id", typeof(Guid));
table.Columns.Add("Name", typeof(String));
table.Columns.Add("Email", typeof(String));

string str;

for (int i = 0; i < rowCount; i++)
{
str = i.ToString();

row = table.NewRow();
row[0] = Guid.NewGuid();
row[1] = "Name" + str;
row[2] = String.Format("em*************@hotmail.com", str);

table.Rows.Add(row);
}

return table;
}
</script>
-- end code --

hope this helps

Milosz
"Bill" wrote:
Say I want to pull a bunch of records from a contacts database into a
gridview and one of the fields contains an email address. Now suppose
I want to make that email address clickable by putting it in a string
(strEmail) and wrapping it in a hyperlink like this ASP Classic
example...
"<a href='mailto:" & strEmail & "'>" & strEmail & "</a>"

How do I pull that off in a gridview? Step by step or tutorial link
would be great if available.

I am using VS 2005, ASP.Net 2.0 with C# code behind.

Thanks for your help in advance,

Bill

Jan 30 '07 #5

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

Similar topics

5
by: *** HAWK | last post by:
I previously posted but didnt have much response. I have written out what exactly I am trying to do with my ASP site again but hopefully clearer. I am making a site will emulate something like...
7
by: codeslayer | last post by:
Greetings to everyone in ‘forum-land': I have a problem that has plaguing me to no end. It is a CSS-related question, and I have not seen this question posted anywhere in forums or through...
1
by: Brandon | last post by:
A newbie question for you all: Suppose you have a webpage with two frames: a main frame, and a second frame. You have several hyperlinks to other websites in the second frame. What you want is...
7
by: Chris | last post by:
Hi, I am writing a webpage in C#. Visual Studio .NET. the following code does not provide me with intellisence on the context, session, and page.cache. When I put the large if...then...
5
by: Richard | last post by:
I've created a simple web project, which works great on my local machine. Every page works correctly (hyperlinks, textboxes, validator controls, etc.). I've tried both the X-Copy method and a setup...
4
by: Seefor | last post by:
Hi, I want my text hyperlinks to have a dotted border underneath, so I did this which works fine: a, a:link, a:visited, a:hover, a:active { color: #000; text-decoration: none;
3
by: silversubey | last post by:
Hello All I have an Excel 2003 worksheet that has a column of hyperlinks that point to a web-based program. The hyperlinks are dynamic and work fine. Is it possible to have Excel use Firefox to...
15
by: Prisoner at War | last post by:
Okay, I'd like to create a print-friendly website, so I've been reading up on how to create print-friendly pages (without duplicating my site, of course, by having separate versions of each...
15
by: Keith G Hicks | last post by:
I'm not sure what I'm doing wrong. Here's my code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim hyp As HyperLink =...
1
by: Rajpreet | last post by:
Hi All, I have a document where in there are many hyperlinks pointing to files located in a paticular directory. My concern is, if these files are moved from this directory to some other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.