views:

166

answers:

3

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 ?

+1  A: 

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()

p.campbell
And now.. how do I add more fields to the querystring as well ?
MarceloRamires
@MarceloRamires: I've updated the answer now regarding multiple fields.
p.campbell
A: 

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

Matthew Jones
A: 

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")) %>'

MStodd
NavigateUrl='<%# String.Concat("~/Admin/Teste/Teste.aspx?rac=", Eval("idApontamento")) %>' you were missing a ).
ggonsalv
got it, thanks.
MStodd