0

I have a gridview in which I want to load a users details. In this gridview I want to make the users phone number a hyperlink. This is so they can click on the link and it automatically rings the number using the phone software stored on the their pc. This works fine if you use the below syntax in html:

   <a href = "tel:07123456789">07123456789</a>

My issue is that I want to do this in a gridview which populattes the phone number. The html has to have the 'tel:' bit in front of it first. I have tried everything please help! I want essentially above but to render in gridview with the loaded HomeNo where the phone number should be...HElp! Gridview:

   <asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="ds">
           <Columns>

               <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
               <asp:HyperLinkField DataTextField="HomeNo" HeaderText="HomeNo" NavigateUrl="tel:"  />
            </Columns>
       </asp:GridView>
wubblyjuggly
  • 919
  • 3
  • 13
  • 33

2 Answers2

3
<asp:GridView ID="GridView1" runat="server"  OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="ds">
   <Columns>
      <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
      <asp:TemplateField>
         <ItemTemplate>
           <asp:HyperLink ID="HyperLink1" runat="server" 
                NavigateUrl='<%# Eval("HomeNo", "tel:{0}") %>' 
                       Text='<%# Eval("NomeNo") %>'></asp:HyperLink>
         </ItemTemplate>
      </asp:TemplateField>
   </Columns>
</asp:GridView>
fnostro
  • 4,531
  • 1
  • 15
  • 23
2

you would need to do this inside of an also if you have data it's reading from you need to do some code inside of the DataBound Event of the DataGrid

for example I have names and email addresses as a link in my current datagrid here is how I do it

<asp:TemplateColumn HeaderText="Scheduler" HeaderStyle-Font-Bold="true" HeaderStyle-Width="145">
    <ItemTemplate>
        <a href='<%#Eval("Email_Address") %>' ><%# Eval("Scheduler") %></a>
    </ItemTemplate>
    <HeaderStyle Font-Bold="True" />
</asp:TemplateColumn>

protected void dgShippers_DataBinding(object sender, EventArgs e)
{
    foreach (DataRow r in dtShippers.Rows)
    {
        if (!System.Uri.IsWellFormedUriString(r.ItemArray[3].ToString(), UriKind.Absolute))
        {
            var tempHref = "<a href=mailto:" + r.ItemArray[4].ToString() + " />" + r.ItemArray[3].ToString()+ "</a>";
            r.Table.Rows[0]["Scheduler"] = tempHref;
        }
    }
}
MethodMan
  • 18,625
  • 6
  • 34
  • 52