Create HyperLink in GridView in ASP.NET Web Forms - Eval not working

I have a gridview with a template field with HyperLink:

<asp:TemplateField ItemStyle-Width="12%" HeaderText="VER" HeaderStyle-HorizontalAlign="Center" SortExpression="Ver" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>  
       <asp:HyperLink ID="HyperLink1" NavigateUrl="~/Admin/Teste/Teste.aspx?rac=<%#Eval('idApontamento')%>" runat="server">TEXT</asp:HyperLink>
    </ItemTemplate> 
</asp:TemplateField>

      

I am getting The server tag is not well formed.

in line HyperLink.

What can I do to directly create a request in HyperLink?

+2


a source to share


3 answers


Create your hyperlink like this:

<asp:HyperLinkField HeaderText="Title"
  DataTextField="Some Text"
  DataNavigateUrlFields="idApontamento,CustomerID" 
  DataNavigateUrlFormatString="~/Admin/Teste/Teste.aspx?rac={0}&CustomerID={1}" />

      



Keep adding comma delimited values ​​to the property DataNavigateUrlFields

and mark up DataNavigateUrlFormatString

as you wouldstring.Format()

+9


a source


I don't think you can insert such an expression, you should choose to pass all the text or all the required expressions.

Fortunately, you can match the string in the binding expression. Try something like this:



NavigateUrl = '<% # String.Concat ("~ / Admin / Teste / Teste.aspx? Rac =", Eval ("idApontamento"))%>'

+3


a source


You have an extra double quote after the pound symbol (#). Does deleting help?

0


a source







All Articles