开发者

Inline coding control's property

IS it possilbe to inline code a porperty like Font-bold of control like linkbutton?

Font-Bold="<%=(Display==1)开发者_开发问答? true:false%>"

this doesn't work.

Cannot create an object of type 'System.Boolean' from its string representation '<%=(Display==2)? true:false%>' for the 'Bold' property.


You can only do this with data binding expressions:

Font-Bold="<%# (Display==1)? true:false %>"

Note the <%# instead of the <%=

And then you have to call DataBind() on the control or one of its containers.


No, you can't use inline code on attributes of Runat="server" elements.

Use the PreRender event of the page. Assuming the linkbutton has ID="myLinkButton" :-

 myLinkButton.Font.Bold = (Display == 1);


Try it with single quotes.

E.g.

Font-Bold='<%....


You can add this functionality with a custom ExpressionBuilder, but it doesn't come standard.

With the CodeExpressionBuilder example you can use the syntax Text="<%$ Code: DateTime.Now %>"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜