开发者

ASP.NET view engine won't execute my code snippets

开发者 https://www.devze.com 2022-12-16 16:12 出处:网络
I have an asp:DataGrid with templated columns. Here\'s one of those columns: <asp:TemplateColumn>

I have an asp:DataGrid with templated columns. Here's one of those columns:

<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="btnDetails"
    Runat="server" 
    CommandName="details" 
    Text="Details"
    Font-Size="0.8em"
    CommandArgument='a=<%# Eval("a")%>&amp;b=<%# Eval("b")%>' />
<...>

When the command fires, the CommandArgument comes back unevaluated - it is the str开发者_JS百科ing a=<%# Eval("a")%>&b=<%# Eval("b")%>, not a=5&b=6 as I want.

What's wrong with how I'm doing this?


Yeah Mitch is correct, if you want another way:

CommandArgument='<%# String.Format("a={0}&b={1}",
  DataBinder.Eval(Container.DataItem, "a"), 
  DataBinder.Eval(Container.DataItem, "b")) %>'

DataBind has to be called, or those substitutions won't happen...


<%# Eval() %> is a databinding expression. You can't concatenate it with another string outside of the eval expression.

0

精彩评论

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