开发者

Inline coding control's property

开发者 https://www.devze.com 2022-12-09 23:58 出处:网络
IS it possilbe to inline code a porperty like Font-bold of control like linkbutton? Font-Bold=\"<%=(Display==1)开发者_开发问答?

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

精彩评论

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