I am inside a Repeater, and I'm trying to call the IsExperienced function from CssClass (as I usually do):

<asp:LinkButton 
    ID="CheckBox" 
    CssClass='wall-item-checkbox <%# IsExperienced() %>' 
    runat="server" 
    onclick="CallFunction">
    &nbsp;
</asp:LinkButton>

but this time it prints class=wall-item-checkbox <%# IsExperienced() %> on the HTML.

有帮助吗?

解决方案

Seems like an odd approach in the first place given that you can access that control within the repeater ItemDataBound event, better to separate code from markup.

Why don't you do this instead:

protected void fooRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
    {
        LinkButton lnkButton = (LinkButton)e.Item.FindControl("CheckBox");
        lnkButton.CssClass += string.Format(" {0}", IsExperienced());
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top