Tuesday, February 8, 2011

Eval scripts in server side control property

how do i implement an eval script in a sever side control?

eg. <a runat="server" href="?id=<%= Eval("Id") %>">hello world</a>

  • <%# Eval("Id") %>

    as far as I know, its <%# instead of <%=

    From Robinb
  • The Data-Binding expression is your friend, see MSDN for examples.

    From snomag
  • If the server-side control is within a databound control (ListView, GridView, FormView, DetailsView), then the syntax is: <%# Eval("Id") %>.

    If the server-side control is not within a databound control, you will have to access it via the code-behind and set your attribute there.

0 comments:

Post a Comment