mailto: in datagrid hyperlink

G

Guest

In asp.net 2.0 I have created a datagrid. The databind is to a table with a
column called email in it. In designer, I am adding columns . I have added a
column "email" with the following parms:
HeaderText:Email
DataNavigateUrlField:email
DataNavigateUrlFormatString:mailto:{0}
DataTextField:email
ItemStyle | CssClass:gridlink
Nothing else has been set.
I expected the result to be a link that would open the default mail client.
Instead the text appears in the grid but the HTML tag generated is just
<a>[email protected]</a>
ie no mailto has appeared. Is this the expected behaviour, am I doing
something wrong?
 
G

Guest

Hi Sam,


Try fllowing code in RowDataBound event

if (e.Row.RowType == DataControlRowType.DataRow)
{

HyperLink link = (HyperLink)e.Row.Cells[col_index].Controls[0];
DataRowView drv = (DataRowView)e.Row.DataItem;
link.NavigateUrl = "mailto:" + drv[col_index].ToString()
}

HTH

Elton Wang
 
G

Guest

Elton W
Thanks for the reply. What you suggest is similar to what I have done to
work around the problem. I am still none the wiser as to why the original
method does not work, and for future occassions would like to know, if only
to avaiod the extra coding!!

Thanks

Sam

Elton W said:
Hi Sam,


Try fllowing code in RowDataBound event

if (e.Row.RowType == DataControlRowType.DataRow)
{

HyperLink link = (HyperLink)e.Row.Cells[col_index].Controls[0];
DataRowView drv = (DataRowView)e.Row.DataItem;
link.NavigateUrl = "mailto:" + drv[col_index].ToString()
}

HTH

Elton Wang


sam said:
In asp.net 2.0 I have created a datagrid. The databind is to a table with a
column called email in it. In designer, I am adding columns . I have added a
column "email" with the following parms:
HeaderText:Email
DataNavigateUrlField:email
DataNavigateUrlFormatString:mailto:{0}
DataTextField:email
ItemStyle | CssClass:gridlink
Nothing else has been set.
I expected the result to be a link that would open the default mail client.
Instead the text appears in the grid but the HTML tag generated is just
<a>[email protected]</a>
ie no mailto has appeared. Is this the expected behaviour, am I doing
something wrong?
 
G

Guest

In the end I went for setting email as the DataTextField and then putting
the entire tag in the DataTextFormatString - which worked fine: ie
DataTextFormatString =<a href=mailto:{0:G}?subject=mySubject - >{0:G}</a>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top