samuel
samuel

Reputation: 321

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.

Upvotes: 3

Views: 949

Answers (4)

Greg
Greg

Reputation: 16680

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 %>"

Upvotes: 0

Ray
Ray

Reputation: 21905

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.

Upvotes: 2

AnthonyWJones
AnthonyWJones

Reputation: 189467

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);

Upvotes: 0

Keith Adler
Keith Adler

Reputation: 21178

Try it with single quotes.

E.g.

Font-Bold='<%....

Upvotes: 0

Related Questions