开发者

ASP.NET binding to a UserControl property

开发者 https://www.devze.com 2022-12-08 02:31 出处:网络
This should be real开发者_C百科ly easy but I can\'t figure out how to make it work... I have an ASP.NET UserControl (.ascx) with the following property:

This should be real开发者_C百科ly 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


I think what you might want is this:

   <td class="<%=LabelCssClass%>">


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.

0

精彩评论

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