开发者

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

开发者 https://www.devze.com 2022-12-28 10:28 出处:网络
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-

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:TemplateFie开发者_如何学编程ld>

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 ?


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消