Marcelo
Marcelo

Reputation: 3391

Build a HyperLink in a GridView in ASP.NET webforms - Eval not working

I have a gridview with a template field that has a 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 the HyperLink line.

What should I do in order to directly build a querystring in a HyperLink ?

Upvotes: 2

Views: 8914

Answers (3)

p.campbell
p.campbell

Reputation: 100607

Build 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 DataNavigateUrlFields property, and markup the DataNavigateUrlFormatString as you would string.Format()

Upvotes: 9

MStodd
MStodd

Reputation: 4746

I don't think you can embed an expression like that, you have to pick to give it all text, or all binding expression.

Thankfully, you can contatonate string in a binding expression. Try something like this:

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

Upvotes: 3

Matthew Jones
Matthew Jones

Reputation: 26190

You've got an extra double-quote after the pound (#) symbol. Does removing that help?

Upvotes: 0

Related Questions