views:

261

answers:

2

This should be really easy but I can't figure out how to make it work...

I have an ASP.NET UserControl (.ascx) with the following property:

public string LabelCssClass
{
    get
    {
        return _labelCssClass;
    }
    set
    {
        _labelCssClass = value;
    }
}

I want to bind that property into the HTML of the UserControl at run time, using the <%# syntax. I imagine it must be something along these lines:

<td class="<%# Eval("LabelCssClass") %>" >

I've tried all different versions of Eval() and so on ... I'm not getting errors but the binding isn't working, and my breakpoints show that the property is not being accessed.

Whats the correct syntax? cheers

+3  A: 

I think what you might want is this:

   <td class="<%=LabelCssClass%>">
Kevin
Thats the one! Thanks. What is the name of the '<%=' type of binding, versus the '<%#' type? ... I had real trouble looking up help for this ...
codeulike
It's not binding. <%= is shorthand for Response.Write().
Kevin
Oh yeah : S ... I'm so used to thinking of the yellow <% things as being about binding that I forget you can also embed code ... thanks
codeulike
+1  A: 

Kevin's answer is probably closer to what you are trying to achieve; however, you can successfully use the <%# %> syntax in the standard markup if you call DataBind() on the Page itself.

Nathan Taylor