ASP:LinkButton and Eval
Asked Answered
S

1

5

I'm using an ASP:LinkButton inside of an ItemTemplate inside of a TemplateField in a GridView. For the command argument for the link button I want to pass the ID of the row from the datasource that the gridview is bound to, so I'm doing something like this:

<asp:LinkButton ID="viewLogButton" CommandName="viewLog" CommandArgument="<%#Eval("ID")%>" Text="View Log" runat="server"/>

Unfortunately, the resulting HTML is this:

<asp:LinkButton ID="viewLogButton" CommandName="viewLog" CommandArgument="3" Text="View Log" runat="server"/>

It seems that it is parsing the Eval() properly, but this is somehow causing it not to parse the LinkButton tag and just dump it out as literal text. Does anyone know:

a) why this is happening and, b) what a good solution to this problem is?

Suffragette answered 23/2, 2009 at 19:16 Comment(2)
"<%#Eval("ID")%>" looks hard to parse.Corbet
Can you post some code. It sounds like your LinkButton might be caught within an Literal control.Standpipe
G
9

While it may not be causing it, I usually define it like this:

CommandArgument='<%#Eval("ID")%>'

Please post the rest of the GridView's markup, as it shouldn't be doing that.

Godfrey answered 23/2, 2009 at 19:22 Comment(4)
silly me, I guess the quotes did it. Thanks. I assumed that all the templates were parsed before the actual asp:* markup - guess not.Suffragette
Just had the same problem and was about to ask the same question.Chatelaine
what would I do without StackOverflow!Pragmatist
sir @Godfrey i have the same problem can you help me out #37500031Sideswipe

© 2022 - 2024 — McMap. All rights reserved.