質問

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