I added this template field to a gridview column and need to access the value, an email address, from the column in code behind. I initially added a DataKeyNames, but this only pulls the first record value. It does not seem to select the value for each record when running through a loop.
I would like to add the email to a label so that I can perhaps use a FindControl statement, unless someone knows of an easier way. I cannot get the email hyperlink to show up in the label. Works fine without the label tag except for not being able to read the email address.
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<a href="mailto:<%# Eval("email") %>"><%#Eval("email")%> </a>
</ItemTemplate>
</asp:TemplateField>
Tried variations of:
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:Label ID="Email99" runat="server" <a href="mailto:<%# Eval("email") %>"><%#Eval("email")%> </a> ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Doesn't show any errors in the inline code, simply reports: Parser Error Message: The server tag is not well formed.
UPDATE: Here is the ASP after adding HyperLinkField to columns
<Columns>
<asp:BoundField DataField="usersLogonName" HeaderText="Logon Name" >
<ControlStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="userDBLanguage" HeaderText="Language" >
<ControlStyle Width="30px" />
</asp:BoundField>
<asp:HyperLinkField runat="server" DataNavigateUrlFields="email" DataNavigateUrlFormatString="mailto:{0}" DataTextField="email" />
<asp:BoundField DataField="LastActivityDate" HeaderText="Last Activity" />
</Columns>
This row of code reads the value from the Templated Field solution provided by James Johnson...
Dim emailAdd As String = GridView4.DataKeys(dr.RowIndex)("Email")
He deserves credit if this thread ever gets unlocked.
This is an ASP page using VB.net
Thanks for any help.