Hello All,
I'm using a WebDataTree with templates and a WebHierarchicalDataSource. One of my templates uses an image button. I am trying to set the CommandArgs to the node's ID so that I can perform a delete on the server. For some reason when I postback to the server, I can't see the CommandArguments. I must be doing the eval wrong for this, although I am able to set the text of a simple lable with the same eval and I see the ID just fine.
Any help would be appreciated.
Doesn't Work
Client:
<asp:ImageButton runat="server" ID="lbActivityDelete" OnClick="lbActivityDelete_Click" ImageUrl="~/images/Delete16.png" AlternateText="Delete Activity" CommandArgument='<%# Eval("ID") %>' ToolTip="Delete Activity" />
Server:
((LinkButton)sender).CommandArgument;
This Works
<asp:Label Text='<%# Eval("ID")%>' runat="server" />
Hi,
I think you should use <%= %>, which passes the evaluated string the HtmlTextWrite.Write() method. Here is a nice article about the meaning of the four available syntaxes: http://michielvoo.net/blog/expressions-vs-statements-part-2-asp-net-code-block-types/
1) <%$ %>2) <%# %>3) <% %>4) <%= %>
Hope that helps,
Lubomir
Lubomir, thanks for the response. Your post was useful in finding my solution. I looked at the link that you provided and it was a great reference to those code blocks... I always use them but never had a good understand of what all of them do.
I still don't understand what the one with the "=" sign does. I tried it in my code and I got the string literal every time.
CommandArgument='<%= Eval("ID") %>' Gets me "<%= Eval("ID") %>" as the command args on the server.
This got me poking around and I remembered that there was another way to bind data in the markup. I remembered that you can use Bind() that will do the same thing as the eval. I believe that one of them allows just reading and the other one allows read/write.
Anyway, I tried it and it worked with the Bind() and the "#" code block.
CommandArgument='<%# Bind("ID") %>' Gets me the ID that I need. Yaaaaa.
Thanks again for your help.