views:

27

answers:

2

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 string a=<%# Eval("a")%>&b=<%# Eval("b")%>, not a=5&b=6 as I want.

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

+1  A: 

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

Mitch Wheat
Oh. Is there an alternative that would do what I'm expecting Eval to do?
Frank Krueger
one option (not necessarily the best one) would be to create a property on some underlying object "CommandArgument" and evaluate it.
Mitch Wheat
@Mitch I was afraid you'd say that. Right now I'm simply bound to a DataView that is bound to a stupid StoredProc. Would hate to touch that code...
Frank Krueger
+2  A: 

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...

jspcal
+1. I knew there had to be a better way!
Mitch Wheat
+1,000,000 I owe you one. I edited the post to make a few syntax corrections.
Frank Krueger